Skip to content

Commit

Permalink
Revert "Directly call source.provide instead of going through dyn error"
Browse files Browse the repository at this point in the history
This reverts commit f924c25.
  • Loading branch information
dtolnay committed Sep 13, 2022
1 parent 21198c9 commit 3bcad59
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 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.provide(#demand);
source.as_dyn_error().provide(#demand);
}
}
} else {
quote_spanned! {source.span()=>
self.#source.provide(#demand);
self.#source.as_dyn_error().provide(#demand);
}
};
let self_provide = if source == backtrace {
Expand All @@ -89,8 +89,7 @@ fn impl_struct(input: Struct) -> TokenStream {
})
};
quote! {
#[allow(unused_imports)]
use std::error::Error as _;
use thiserror::__private::AsDynError;
#source_provide
#self_provide
}
Expand Down Expand Up @@ -260,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.provide(#demand);
source.as_dyn_error().provide(#demand);
}
}
} else {
quote_spanned! {source.span()=>
#varsource.provide(#demand);
#varsource.as_dyn_error().provide(#demand);
}
};
let self_provide = if type_is_option(backtrace_field.ty) {
Expand All @@ -285,8 +284,7 @@ fn impl_enum(input: Enum) -> TokenStream {
#source: #varsource,
..
} => {
#[allow(unused_imports)]
use std::error::Error as _;
use thiserror::__private::AsDynError;
#source_provide
#self_provide
}
Expand All @@ -300,18 +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.provide(#demand);
source.as_dyn_error().provide(#demand);
}
}
} else {
quote_spanned! {backtrace.span()=>
#varsource.provide(#demand);
#varsource.as_dyn_error().provide(#demand);
}
};
quote! {
#ty::#ident {#backtrace: #varsource, ..} => {
#[allow(unused_imports)]
use std::error::Error as _;
use thiserror::__private::AsDynError;
#source_provide
}
}
Expand Down

0 comments on commit 3bcad59

Please sign in to comment.