mirror of
https://github.com/dtolnay/thiserror.git
synced 2025-04-06 06:17:39 +03:00
Extract combined backtrace-source case to separate match arm
This commit is contained in:
parent
d49c5af10f
commit
799bb53b10
1 changed files with 26 additions and 24 deletions
|
@ -240,34 +240,36 @@ fn impl_enum(input: Enum) -> TokenStream {
|
|||
}
|
||||
}
|
||||
}
|
||||
(Some(backtrace_field), _) => {
|
||||
(Some(backtrace_field), Some(source_field))
|
||||
if backtrace_field.member == source_field.member =>
|
||||
{
|
||||
let backtrace = &backtrace_field.member;
|
||||
if variant.source_field().map_or(false, |f| f.member == *backtrace) {
|
||||
let varsource = quote!(source);
|
||||
let source_backtrace = if type_is_option(backtrace_field.ty) {
|
||||
quote_spanned! {backtrace.span()=>
|
||||
#varsource.as_ref().and_then(|source| source.as_dyn_error().backtrace())
|
||||
}
|
||||
} else {
|
||||
quote_spanned! {backtrace.span()=>
|
||||
#varsource.as_dyn_error().backtrace()
|
||||
}
|
||||
};
|
||||
quote! {
|
||||
#ty::#ident {#backtrace: #varsource, ..} => {
|
||||
use thiserror::private::AsDynError;
|
||||
#source_backtrace
|
||||
}
|
||||
let varsource = quote!(source);
|
||||
let source_backtrace = if type_is_option(source_field.ty) {
|
||||
quote_spanned! {backtrace.span()=>
|
||||
#varsource.as_ref().and_then(|source| source.as_dyn_error().backtrace())
|
||||
}
|
||||
} else {
|
||||
let body = if type_is_option(backtrace_field.ty) {
|
||||
quote!(backtrace.as_ref())
|
||||
} else {
|
||||
quote!(std::option::Option::Some(backtrace))
|
||||
};
|
||||
quote! {
|
||||
#ty::#ident {#backtrace: backtrace, ..} => #body,
|
||||
quote_spanned! {backtrace.span()=>
|
||||
#varsource.as_dyn_error().backtrace()
|
||||
}
|
||||
};
|
||||
quote! {
|
||||
#ty::#ident {#backtrace: #varsource, ..} => {
|
||||
use thiserror::private::AsDynError;
|
||||
#source_backtrace
|
||||
}
|
||||
}
|
||||
}
|
||||
(Some(backtrace_field), _) => {
|
||||
let backtrace = &backtrace_field.member;
|
||||
let body = if type_is_option(backtrace_field.ty) {
|
||||
quote!(backtrace.as_ref())
|
||||
} else {
|
||||
quote!(std::option::Option::Some(backtrace))
|
||||
};
|
||||
quote! {
|
||||
#ty::#ident {#backtrace: backtrace, ..} => #body,
|
||||
}
|
||||
}
|
||||
(None, _) => quote! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue