Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly call source.provide instead of going through dyn error #184

Merged
merged 1 commit into from Sep 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions impl/src/expand.rs
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.provide(#demand);
}
}
} else {
quote_spanned! {source.span()=>
self.#source.as_dyn_error().provide(#demand);
self.#source.provide(#demand);
}
};
let self_provide = if source == backtrace {
Expand All @@ -89,7 +89,8 @@ fn impl_struct(input: Struct) -> TokenStream {
})
};
quote! {
use thiserror::__private::AsDynError;
#[allow(unused_imports)]
use std::error::Error as _;
#source_provide
#self_provide
}
Expand Down Expand Up @@ -259,12 +260,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.provide(#demand);
}
}
} else {
quote_spanned! {source.span()=>
#varsource.as_dyn_error().provide(#demand);
#varsource.provide(#demand);
}
};
let self_provide = if type_is_option(backtrace_field.ty) {
Expand All @@ -284,7 +285,8 @@ fn impl_enum(input: Enum) -> TokenStream {
#source: #varsource,
..
} => {
use thiserror::__private::AsDynError;
#[allow(unused_imports)]
use std::error::Error as _;
#source_provide
#self_provide
}
Expand All @@ -298,17 +300,18 @@ 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.provide(#demand);
}
}
} else {
quote_spanned! {backtrace.span()=>
#varsource.as_dyn_error().provide(#demand);
#varsource.provide(#demand);
}
};
quote! {
#ty::#ident {#backtrace: #varsource, ..} => {
use thiserror::__private::AsDynError;
#[allow(unused_imports)]
use std::error::Error as _;
#source_provide
}
}
Expand Down