From 3bcad5957d22c0331dbb65580eb42b66daf782f3 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 5 Sep 2022 14:31:18 -0700 Subject: [PATCH] Revert "Directly call source.provide instead of going through dyn error" This reverts commit f924c251ecae1b4cce08422ed5f7a7eb69776ff9. --- impl/src/expand.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/impl/src/expand.rs b/impl/src/expand.rs index fac6d6f..f2f7116 100644 --- a/impl/src/expand.rs +++ b/impl/src/expand.rs @@ -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 { @@ -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 } @@ -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) { @@ -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 } @@ -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 } }