Skip to content

Commit e0e9943

Browse files
committed
Access Error trait exclusively through ::thiserror
1 parent db7825e commit e0e9943

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

impl/src/expand.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn fallback(input: &DeriveInput, error: syn::Error) -> TokenStream {
3737

3838
#[allow(unused_qualifications)]
3939
#[automatically_derived]
40-
impl #impl_generics ::std::error::Error for #ty #ty_generics #where_clause
40+
impl #impl_generics ::thiserror::__private::Error for #ty #ty_generics #where_clause
4141
where
4242
// Work around trivial bounds being unstable.
4343
// https://github.com/rust-lang/rust/issues/48214
@@ -62,17 +62,17 @@ fn impl_struct(input: Struct) -> TokenStream {
6262
let source_body = if let Some(transparent_attr) = &input.attrs.transparent {
6363
let only_field = &input.fields[0];
6464
if only_field.contains_generic {
65-
error_inferred_bounds.insert(only_field.ty, quote!(::std::error::Error));
65+
error_inferred_bounds.insert(only_field.ty, quote!(::thiserror::__private::Error));
6666
}
6767
let member = &only_field.member;
6868
Some(quote_spanned! {transparent_attr.span=>
69-
::std::error::Error::source(self.#member.as_dyn_error())
69+
::thiserror::__private::Error::source(self.#member.as_dyn_error())
7070
})
7171
} else if let Some(source_field) = input.source_field() {
7272
let source = &source_field.member;
7373
if source_field.contains_generic {
7474
let ty = unoptional_type(source_field.ty);
75-
error_inferred_bounds.insert(ty, quote!(::std::error::Error + 'static));
75+
error_inferred_bounds.insert(ty, quote!(::thiserror::__private::Error + 'static));
7676
}
7777
let asref = if type_is_option(source_field.ty) {
7878
Some(quote_spanned!(source.span()=> .as_ref()?))
@@ -90,7 +90,7 @@ fn impl_struct(input: Struct) -> TokenStream {
9090
};
9191
let source_method = source_body.map(|body| {
9292
quote! {
93-
fn source(&self) -> ::core::option::Option<&(dyn ::std::error::Error + 'static)> {
93+
fn source(&self) -> ::core::option::Option<&(dyn ::thiserror::__private::Error + 'static)> {
9494
use ::thiserror::__private::AsDynError as _;
9595
#body
9696
}
@@ -218,7 +218,7 @@ fn impl_struct(input: Struct) -> TokenStream {
218218
quote! {
219219
#[allow(unused_qualifications)]
220220
#[automatically_derived]
221-
impl #impl_generics ::std::error::Error for #ty #ty_generics #error_where_clause {
221+
impl #impl_generics ::thiserror::__private::Error for #ty #ty_generics #error_where_clause {
222222
#source_method
223223
#provide_method
224224
}
@@ -238,11 +238,11 @@ fn impl_enum(input: Enum) -> TokenStream {
238238
if let Some(transparent_attr) = &variant.attrs.transparent {
239239
let only_field = &variant.fields[0];
240240
if only_field.contains_generic {
241-
error_inferred_bounds.insert(only_field.ty, quote!(::std::error::Error));
241+
error_inferred_bounds.insert(only_field.ty, quote!(::thiserror::__private::Error));
242242
}
243243
let member = &only_field.member;
244244
let source = quote_spanned! {transparent_attr.span=>
245-
::std::error::Error::source(transparent.as_dyn_error())
245+
::thiserror::__private::Error::source(transparent.as_dyn_error())
246246
};
247247
quote! {
248248
#ty::#ident {#member: transparent} => #source,
@@ -251,7 +251,7 @@ fn impl_enum(input: Enum) -> TokenStream {
251251
let source = &source_field.member;
252252
if source_field.contains_generic {
253253
let ty = unoptional_type(source_field.ty);
254-
error_inferred_bounds.insert(ty, quote!(::std::error::Error + 'static));
254+
error_inferred_bounds.insert(ty, quote!(::thiserror::__private::Error + 'static));
255255
}
256256
let asref = if type_is_option(source_field.ty) {
257257
Some(quote_spanned!(source.span()=> .as_ref()?))
@@ -272,7 +272,7 @@ fn impl_enum(input: Enum) -> TokenStream {
272272
}
273273
});
274274
Some(quote! {
275-
fn source(&self) -> ::core::option::Option<&(dyn ::std::error::Error + 'static)> {
275+
fn source(&self) -> ::core::option::Option<&(dyn ::thiserror::__private::Error + 'static)> {
276276
use ::thiserror::__private::AsDynError as _;
277277
#[allow(deprecated)]
278278
match self {
@@ -483,7 +483,7 @@ fn impl_enum(input: Enum) -> TokenStream {
483483
quote! {
484484
#[allow(unused_qualifications)]
485485
#[automatically_derived]
486-
impl #impl_generics ::std::error::Error for #ty #ty_generics #error_where_clause {
486+
impl #impl_generics ::thiserror::__private::Error for #ty #ty_generics #error_where_clause {
487487
#source_method
488488
#provide_method
489489
}

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -287,4 +287,6 @@ pub mod __private {
287287
#[cfg(error_generic_member_access)]
288288
#[doc(hidden)]
289289
pub use crate::provide::ThiserrorProvide;
290+
#[doc(hidden)]
291+
pub use std::error::Error;
290292
}

0 commit comments

Comments
 (0)