@@ -2,8 +2,8 @@ use proc_macro2::TokenStream;
22use quote:: { format_ident, quote, quote_spanned, ToTokens } ;
33use syn:: spanned:: Spanned ;
44use syn:: {
5- parse_macro_input, parse_quote, Attribute , Data , DeriveInput , Fields , GenericParam , Generics ,
6- Ident , Index , Lit , Meta , MetaNameValue , NestedMeta ,
5+ parse_macro_input, parse_quote, Attribute , Data , DeriveInput , Expr , ExprLit , ExprPath ,
6+ Fields , GenericParam , Generics , Ident , Index , Lit , Meta , MetaNameValue ,
77} ;
88
99
@@ -81,33 +81,33 @@ struct Attributes {
8181impl Attributes {
8282 fn parse ( attrs : & [ Attribute ] ) -> Self {
8383 let mut out = Self :: default ( ) ;
84- for attr in attrs. iter ( ) . filter ( |a| a. path . is_ident ( "visit" ) ) {
85- let meta = attr. parse_meta ( ) . expect ( "visit attribute" ) ;
86- match meta {
87- Meta :: List ( l) => {
88- for nested in & l. nested {
89- match nested {
90- NestedMeta :: Meta ( Meta :: NameValue ( v) ) => out. parse_name_value ( v) ,
91- _ => panic ! ( "Expected #[visit(key = \" value\" )]" ) ,
92- }
93- }
84+ for attr in attrs {
85+ if let Meta :: NameValue ( ref namevalue) = attr. meta {
86+ if namevalue. path . is_ident ( "visit" ) {
87+ out. parse_name_value ( namevalue) ;
9488 }
95- _ => panic ! ( "Expected #[visit(...)]" ) ,
9689 }
9790 }
91+ if out. with . is_none ( ) {
92+ panic ! ( "Expected #[visit(...)]" ) ;
93+ }
9894 out
9995 }
10096
10197 /// Updates self with a name value attribute
10298 fn parse_name_value ( & mut self , v : & MetaNameValue ) {
103- if v. path . is_ident ( "with" ) {
104- match & v. lit {
105- Lit :: Str ( s) => self . with = Some ( format_ident ! ( "{}" , s. value( ) , span = s. span( ) ) ) ,
106- _ => panic ! ( "Expected a string value, got {}" , v. lit. to_token_stream( ) ) ,
99+ if let Expr :: Assign ( ref assign) = v. value {
100+ if let Expr :: Path ( ExprPath { ref path, .. } ) = * assign. left {
101+ if path. is_ident ( "with" ) {
102+ match * assign. right {
103+ Expr :: Lit ( ExprLit { lit : Lit :: Str ( ref s) , .. } ) => self . with = Some ( format_ident ! ( "{}" , s. value( ) , span = s. span( ) ) ) ,
104+ _ => panic ! ( "Expected a string value, got {}" , v. value. to_token_stream( ) ) ,
105+ }
106+ return ;
107+ }
107108 }
108- return ;
109109 }
110- panic ! ( "Unrecognised kv attribute {}" , v. path . to_token_stream( ) )
110+ panic ! ( "Unrecognised kv attribute {}" , v. to_token_stream( ) )
111111 }
112112
113113 /// Returns the pre and post visit token streams
0 commit comments