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

Access all std types through absolute path #369

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions impl/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn fallback(input: &DeriveInput, error: syn::Error) -> TokenStream {

#[allow(unused_qualifications)]
#[automatically_derived]
impl #impl_generics std::error::Error for #ty #ty_generics #where_clause
impl #impl_generics ::std::error::Error for #ty #ty_generics #where_clause
where
// Work around trivial bounds being unstable.
// https://github.com/rust-lang/rust/issues/48214
Expand All @@ -62,17 +62,17 @@ fn impl_struct(input: Struct) -> TokenStream {
let source_body = if let Some(transparent_attr) = &input.attrs.transparent {
let only_field = &input.fields[0];
if only_field.contains_generic {
error_inferred_bounds.insert(only_field.ty, quote!(std::error::Error));
error_inferred_bounds.insert(only_field.ty, quote!(::std::error::Error));
}
let member = &only_field.member;
Some(quote_spanned! {transparent_attr.span=>
std::error::Error::source(self.#member.as_dyn_error())
::std::error::Error::source(self.#member.as_dyn_error())
})
} else if let Some(source_field) = input.source_field() {
let source = &source_field.member;
if source_field.contains_generic {
let ty = unoptional_type(source_field.ty);
error_inferred_bounds.insert(ty, quote!(std::error::Error + 'static));
error_inferred_bounds.insert(ty, quote!(::std::error::Error + 'static));
}
let asref = if type_is_option(source_field.ty) {
Some(quote_spanned!(source.span()=> .as_ref()?))
Expand All @@ -90,7 +90,7 @@ fn impl_struct(input: Struct) -> TokenStream {
};
let source_method = source_body.map(|body| {
quote! {
fn source(&self) -> ::core::option::Option<&(dyn std::error::Error + 'static)> {
fn source(&self) -> ::core::option::Option<&(dyn ::std::error::Error + 'static)> {
use ::thiserror::__private::AsDynError as _;
#body
}
Expand Down Expand Up @@ -118,12 +118,12 @@ fn impl_struct(input: Struct) -> TokenStream {
} else if type_is_option(backtrace_field.ty) {
Some(quote! {
if let ::core::option::Option::Some(backtrace) = &self.#backtrace {
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
#request.provide_ref::<::std::backtrace::Backtrace>(backtrace);
}
})
} else {
Some(quote! {
#request.provide_ref::<std::backtrace::Backtrace>(&self.#backtrace);
#request.provide_ref::<::std::backtrace::Backtrace>(&self.#backtrace);
})
};
quote! {
Expand All @@ -134,16 +134,16 @@ fn impl_struct(input: Struct) -> TokenStream {
} else if type_is_option(backtrace_field.ty) {
quote! {
if let ::core::option::Option::Some(backtrace) = &self.#backtrace {
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
#request.provide_ref::<::std::backtrace::Backtrace>(backtrace);
}
}
} else {
quote! {
#request.provide_ref::<std::backtrace::Backtrace>(&self.#backtrace);
#request.provide_ref::<::std::backtrace::Backtrace>(&self.#backtrace);
}
};
quote! {
fn provide<'_request>(&'_request self, #request: &mut std::error::Request<'_request>) {
fn provide<'_request>(&'_request self, #request: &mut ::std::error::Request<'_request>) {
#body
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ fn impl_struct(input: Struct) -> TokenStream {
quote! {
#[allow(unused_qualifications)]
#[automatically_derived]
impl #impl_generics std::error::Error for #ty #ty_generics #error_where_clause {
impl #impl_generics ::std::error::Error for #ty #ty_generics #error_where_clause {
#source_method
#provide_method
}
Expand All @@ -238,11 +238,11 @@ fn impl_enum(input: Enum) -> TokenStream {
if let Some(transparent_attr) = &variant.attrs.transparent {
let only_field = &variant.fields[0];
if only_field.contains_generic {
error_inferred_bounds.insert(only_field.ty, quote!(std::error::Error));
error_inferred_bounds.insert(only_field.ty, quote!(::std::error::Error));
}
let member = &only_field.member;
let source = quote_spanned! {transparent_attr.span=>
std::error::Error::source(transparent.as_dyn_error())
::std::error::Error::source(transparent.as_dyn_error())
};
quote! {
#ty::#ident {#member: transparent} => #source,
Expand All @@ -251,7 +251,7 @@ fn impl_enum(input: Enum) -> TokenStream {
let source = &source_field.member;
if source_field.contains_generic {
let ty = unoptional_type(source_field.ty);
error_inferred_bounds.insert(ty, quote!(std::error::Error + 'static));
error_inferred_bounds.insert(ty, quote!(::std::error::Error + 'static));
}
let asref = if type_is_option(source_field.ty) {
Some(quote_spanned!(source.span()=> .as_ref()?))
Expand All @@ -272,7 +272,7 @@ fn impl_enum(input: Enum) -> TokenStream {
}
});
Some(quote! {
fn source(&self) -> ::core::option::Option<&(dyn std::error::Error + 'static)> {
fn source(&self) -> ::core::option::Option<&(dyn ::std::error::Error + 'static)> {
use ::thiserror::__private::AsDynError as _;
#[allow(deprecated)]
match self {
Expand Down Expand Up @@ -309,12 +309,12 @@ fn impl_enum(input: Enum) -> TokenStream {
let self_provide = if type_is_option(backtrace_field.ty) {
quote! {
if let ::core::option::Option::Some(backtrace) = backtrace {
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
#request.provide_ref::<::std::backtrace::Backtrace>(backtrace);
}
}
} else {
quote! {
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
#request.provide_ref::<::std::backtrace::Backtrace>(backtrace);
}
};
quote! {
Expand Down Expand Up @@ -357,12 +357,12 @@ fn impl_enum(input: Enum) -> TokenStream {
let body = if type_is_option(backtrace_field.ty) {
quote! {
if let ::core::option::Option::Some(backtrace) = backtrace {
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
#request.provide_ref::<::std::backtrace::Backtrace>(backtrace);
}
}
} else {
quote! {
#request.provide_ref::<std::backtrace::Backtrace>(backtrace);
#request.provide_ref::<::std::backtrace::Backtrace>(backtrace);
}
};
quote! {
Expand All @@ -377,7 +377,7 @@ fn impl_enum(input: Enum) -> TokenStream {
}
});
Some(quote! {
fn provide<'_request>(&'_request self, #request: &mut std::error::Request<'_request>) {
fn provide<'_request>(&'_request self, #request: &mut ::std::error::Request<'_request>) {
#[allow(deprecated)]
match self {
#(#arms)*
Expand Down Expand Up @@ -483,7 +483,7 @@ fn impl_enum(input: Enum) -> TokenStream {
quote! {
#[allow(unused_qualifications)]
#[automatically_derived]
impl #impl_generics std::error::Error for #ty #ty_generics #error_where_clause {
impl #impl_generics ::std::error::Error for #ty #ty_generics #error_where_clause {
#source_method
#provide_method
}
Expand Down Expand Up @@ -532,11 +532,11 @@ fn from_initializer(
let backtrace_member = &backtrace_field.member;
if type_is_option(backtrace_field.ty) {
quote! {
#backtrace_member: ::core::option::Option::Some(std::backtrace::Backtrace::capture()),
#backtrace_member: ::core::option::Option::Some(::std::backtrace::Backtrace::capture()),
}
} else {
quote! {
#backtrace_member: ::core::convert::From::from(std::backtrace::Backtrace::capture()),
#backtrace_member: ::core::convert::From::from(::std::backtrace::Backtrace::capture()),
}
}
});
Expand Down
Loading