Skip to content

Commit

Permalink
Use ThiserrorProvide to disambiguate 'provide' method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 13, 2022
1 parent 460396e commit aaf8449
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions impl/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -89,7 +89,7 @@ fn impl_struct(input: Struct) -> TokenStream {
})
};
quote! {
use thiserror::__private::AsDynError;
use thiserror::__private::ThiserrorProvide;
#source_provide
#self_provide
}
Expand Down Expand Up @@ -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) {
Expand All @@ -284,7 +284,7 @@ fn impl_enum(input: Enum) -> TokenStream {
#source: #varsource,
..
} => {
use thiserror::__private::AsDynError;
use thiserror::__private::ThiserrorProvide;
#source_provide
#self_provide
}
Expand All @@ -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
}
}
Expand Down

0 comments on commit aaf8449

Please sign in to comment.