@@ -25,6 +25,12 @@ impl Error {
2525 }
2626}
2727
28+ impl From < syn:: Error > for Error {
29+ fn from ( e : syn:: Error ) -> Error {
30+ Error ( e. to_compile_error ( ) )
31+ }
32+ }
33+
2834decl_derive ! ( [ Fail , attributes( fail, cause) ] => fail_derive) ;
2935
3036fn fail_derive ( s : synstructure:: Structure ) -> TokenStream {
@@ -120,7 +126,7 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
120126 }
121127
122128 let format_string = match msg. nested [ 0 ] {
123- syn:: NestedMeta :: Meta ( syn:: Meta :: NameValue ( ref nv) ) if nv. ident == "display" => {
129+ syn:: NestedMeta :: Meta ( syn:: Meta :: NameValue ( ref nv) ) if nv. path . is_ident ( "display" ) => {
124130 nv. lit . clone ( )
125131 }
126132 _ => {
@@ -131,12 +137,12 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
131137 }
132138 } ;
133139 let args = msg. nested . iter ( ) . skip ( 1 ) . map ( |arg| match * arg {
134- syn:: NestedMeta :: Literal ( syn:: Lit :: Int ( ref i) ) => {
135- let bi = & v. bindings ( ) [ i. value ( ) as usize ] ;
140+ syn:: NestedMeta :: Lit ( syn:: Lit :: Int ( ref i) ) => {
141+ let bi = & v. bindings ( ) [ i. base10_parse :: < usize > ( ) ? ] ;
136142 Ok ( quote ! ( #bi) )
137143 }
138- syn:: NestedMeta :: Meta ( syn:: Meta :: Word ( ref id ) ) => {
139- let id_s = id . to_string ( ) ;
144+ syn:: NestedMeta :: Meta ( syn:: Meta :: Path ( ref path ) ) => {
145+ let id_s = path . get_ident ( ) . map ( syn :: Ident :: to_string) . unwrap_or ( "" . to_string ( ) ) ;
140146 if id_s. starts_with ( "_" ) {
141147 if let Ok ( idx) = id_s[ 1 ..] . parse :: < usize > ( ) {
142148 let bi = match v. bindings ( ) . get ( idx) {
@@ -160,15 +166,16 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
160166 }
161167 }
162168 for bi in v. bindings ( ) {
163- if bi. ast ( ) . ident . as_ref ( ) == Some ( id) {
169+ let id = bi. ast ( ) . ident . as_ref ( ) ;
170+ if id. is_some ( ) && path. is_ident ( id. unwrap ( ) ) {
164171 return Ok ( quote ! ( #bi) ) ;
165172 }
166173 }
167174 return Err ( Error :: new (
168175 arg. span ( ) ,
169176 & format ! (
170- "Couldn't find field `{}` in `{}::{}`" ,
171- id ,
177+ "Couldn't find field `{:? }` in `{}::{}`" ,
178+ path ,
172179 s. ast( ) . ident,
173180 v. ast( ) . ident
174181 )
@@ -192,8 +199,8 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
192199fn find_error_msg ( attrs : & [ syn:: Attribute ] ) -> Result < Option < syn:: MetaList > , Error > {
193200 let mut error_msg = None ;
194201 for attr in attrs {
195- if let Some ( meta) = attr. interpret_meta ( ) {
196- if meta. name ( ) == "fail" {
202+ if let Ok ( meta) = attr. parse_meta ( ) {
203+ if meta. path ( ) . is_ident ( "fail" ) {
197204 if error_msg. is_some ( ) {
198205 return Err ( Error :: new (
199206 meta. span ( ) ,
@@ -223,7 +230,7 @@ fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool {
223230 segments : ref path, ..
224231 } ,
225232 } ) => path. last ( ) . map_or ( false , |s| {
226- s. value ( ) . ident == "Backtrace" && s. value ( ) . arguments . is_empty ( )
233+ s. ident == "Backtrace" && s. arguments . is_empty ( )
227234 } ) ,
228235 _ => false ,
229236 }
@@ -232,18 +239,18 @@ fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool {
232239fn is_cause ( bi : & & synstructure:: BindingInfo ) -> bool {
233240 let mut found_cause = false ;
234241 for attr in & bi. ast ( ) . attrs {
235- if let Some ( meta) = attr. interpret_meta ( ) {
236- if meta. name ( ) == "cause" {
242+ if let Ok ( meta) = attr. parse_meta ( ) {
243+ if meta. path ( ) . is_ident ( "cause" ) {
237244 if found_cause {
238245 panic ! ( "Cannot have two `cause` attributes" ) ;
239246 }
240247 found_cause = true ;
241248 }
242- if meta. name ( ) == "fail" {
249+ if meta. path ( ) . is_ident ( "fail" ) {
243250 if let syn:: Meta :: List ( ref list) = meta {
244251 if let Some ( ref pair) = list. nested . first ( ) {
245- if let & & syn:: NestedMeta :: Meta ( syn:: Meta :: Word ( ref word ) ) = pair. value ( ) {
246- if word == "cause" {
252+ if let & & syn:: NestedMeta :: Meta ( syn:: Meta :: Path ( ref path ) ) = pair {
253+ if path . is_ident ( "cause" ) {
247254 if found_cause {
248255 panic ! ( "Cannot have two `cause` attributes" ) ;
249256 }
0 commit comments