Use ThiserrorProvide to disambiguate 'provide' method calls

This commit is contained in:
David Tolnay 2022-09-05 14:45:05 -07:00
parent 460396e8f3
commit aaf8449dcb
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -67,12 +67,12 @@ fn impl_struct(input: Struct) -> TokenStream {
let source_provide = if type_is_option(source_field.ty) {
quote_spanned! {source.span()=>
if let std::option::Option::Some(source) = &self.#source {
source.as_dyn_error().provide(#demand);
source.thiserror_provide(#demand);
}
}
} else {
quote_spanned! {source.span()=>
self.#source.as_dyn_error().provide(#demand);
self.#source.thiserror_provide(#demand);
}
};
let self_provide = if source == backtrace {
@ -89,7 +89,7 @@ fn impl_struct(input: Struct) -> TokenStream {
})
};
quote! {
use thiserror::__private::AsDynError;
use thiserror::__private::ThiserrorProvide;
#source_provide
#self_provide
}
@ -259,12 +259,12 @@ fn impl_enum(input: Enum) -> TokenStream {
let source_provide = if type_is_option(source_field.ty) {
quote_spanned! {source.span()=>
if let std::option::Option::Some(source) = #varsource {
source.as_dyn_error().provide(#demand);
source.thiserror_provide(#demand);
}
}
} else {
quote_spanned! {source.span()=>
#varsource.as_dyn_error().provide(#demand);
#varsource.thiserror_provide(#demand);
}
};
let self_provide = if type_is_option(backtrace_field.ty) {
@ -284,7 +284,7 @@ fn impl_enum(input: Enum) -> TokenStream {
#source: #varsource,
..
} => {
use thiserror::__private::AsDynError;
use thiserror::__private::ThiserrorProvide;
#source_provide
#self_provide
}
@ -298,17 +298,17 @@ fn impl_enum(input: Enum) -> TokenStream {
let source_provide = if type_is_option(source_field.ty) {
quote_spanned! {backtrace.span()=>
if let std::option::Option::Some(source) = #varsource {
source.as_dyn_error().provide(#demand);
source.thiserror_provide(#demand);
}
}
} else {
quote_spanned! {backtrace.span()=>
#varsource.as_dyn_error().provide(#demand);
#varsource.thiserror_provide(#demand);
}
};
quote! {
#ty::#ident {#backtrace: #varsource, ..} => {
use thiserror::__private::AsDynError;
use thiserror::__private::ThiserrorProvide;
#source_provide
}
}