@@ -23,14 +23,14 @@ fn impl_struct(input: Struct) -> TokenStream {
23
23
let ( impl_generics, ty_generics, where_clause) = input. generics . split_for_impl ( ) ;
24
24
let mut error_inferred_bounds = InferredBounds :: new ( ) ;
25
25
26
- let source_body = if input. attrs . transparent . is_some ( ) {
26
+ let source_body = if let Some ( transparent_attr ) = & input. attrs . transparent {
27
27
let only_field = & input. fields [ 0 ] ;
28
28
if only_field. contains_generic {
29
29
error_inferred_bounds. insert ( only_field. ty , quote ! ( std:: error:: Error ) ) ;
30
30
}
31
31
let member = & only_field. member ;
32
- Some ( quote ! {
33
- std:: error:: Error :: source( self . #member. as_dyn_error( ) )
32
+ Some ( quote_spanned ! {
33
+ transparent_attr . span => std:: error:: Error :: source( self . #member. as_dyn_error( ) )
34
34
} )
35
35
} else if let Some ( source_field) = input. source_field ( ) {
36
36
let source = & source_field. member ;
@@ -43,7 +43,8 @@ fn impl_struct(input: Struct) -> TokenStream {
43
43
} else {
44
44
None
45
45
} ;
46
- let dyn_error = quote_spanned ! ( source. span( ) => self . #source #asref. as_dyn_error( ) ) ;
46
+ let dyn_error =
47
+ quote_spanned ! ( source_field. source_span( ) => self . #source #asref. as_dyn_error( ) ) ;
47
48
Some ( quote ! {
48
49
:: core:: option:: Option :: Some ( #dyn_error)
49
50
} )
@@ -193,13 +194,13 @@ fn impl_enum(input: Enum) -> TokenStream {
193
194
let source_method = if input. has_source ( ) {
194
195
let arms = input. variants . iter ( ) . map ( |variant| {
195
196
let ident = & variant. ident ;
196
- if variant. attrs . transparent . is_some ( ) {
197
+ if let Some ( transparent_attr ) = & variant. attrs . transparent {
197
198
let only_field = & variant. fields [ 0 ] ;
198
199
if only_field. contains_generic {
199
200
error_inferred_bounds. insert ( only_field. ty , quote ! ( std:: error:: Error ) ) ;
200
201
}
201
202
let member = & only_field. member ;
202
- let source = quote ! ( std:: error:: Error :: source( transparent. as_dyn_error( ) ) ) ;
203
+ let source = quote_spanned ! ( transparent_attr . span => std:: error:: Error :: source( transparent. as_dyn_error( ) ) ) ;
203
204
quote ! {
204
205
#ty:: #ident { #member: transparent} => #source,
205
206
}
@@ -215,7 +216,7 @@ fn impl_enum(input: Enum) -> TokenStream {
215
216
None
216
217
} ;
217
218
let varsource = quote ! ( source) ;
218
- let dyn_error = quote_spanned ! ( source . span ( ) => #varsource #asref. as_dyn_error( ) ) ;
219
+ let dyn_error = quote_spanned ! ( source_field . source_span ( ) => #varsource #asref. as_dyn_error( ) ) ;
219
220
quote ! {
220
221
#ty:: #ident { #source: #varsource, ..} => :: core:: option:: Option :: Some ( #dyn_error) ,
221
222
}
0 commit comments