Touch up PR 258

This commit is contained in:
David Tolnay 2023-10-19 10:37:00 -07:00
parent 4850c6f80f
commit c9fe739272
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 13 additions and 7 deletions

View file

@ -29,8 +29,8 @@ fn impl_struct(input: Struct) -> TokenStream {
error_inferred_bounds.insert(only_field.ty, quote!(std::error::Error));
}
let member = &only_field.member;
Some(quote_spanned! {
transparent_attr.span => std::error::Error::source(self.#member.as_dyn_error())
Some(quote_spanned! {transparent_attr.span=>
std::error::Error::source(self.#member.as_dyn_error())
})
} else if let Some(source_field) = input.source_field() {
let source = &source_field.member;
@ -43,8 +43,9 @@ fn impl_struct(input: Struct) -> TokenStream {
} else {
None
};
let dyn_error =
quote_spanned!(source_field.source_span() => self.#source #asref.as_dyn_error());
let dyn_error = quote_spanned! {source_field.source_span()=>
self.#source #asref.as_dyn_error()
};
Some(quote! {
::core::option::Option::Some(#dyn_error)
})
@ -200,7 +201,9 @@ fn impl_enum(input: Enum) -> TokenStream {
error_inferred_bounds.insert(only_field.ty, quote!(std::error::Error));
}
let member = &only_field.member;
let source = quote_spanned!(transparent_attr.span => std::error::Error::source(transparent.as_dyn_error()));
let source = quote_spanned! {transparent_attr.span=>
std::error::Error::source(transparent.as_dyn_error())
};
quote! {
#ty::#ident {#member: transparent} => #source,
}
@ -216,7 +219,9 @@ fn impl_enum(input: Enum) -> TokenStream {
None
};
let varsource = quote!(source);
let dyn_error = quote_spanned!(source_field.source_span()=> #varsource #asref.as_dyn_error());
let dyn_error = quote_spanned! {source_field.source_span()=>
#varsource #asref.as_dyn_error()
};
quote! {
#ty::#ident {#source: #varsource, ..} => ::core::option::Option::Some(#dyn_error),
}