Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit 61b1c17

Browse files
committed
error_in_core is stable
1 parent 3663fd1 commit 61b1c17

15 files changed

Lines changed: 18 additions & 50 deletions

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,3 @@ features = ["std"]
3131
[features]
3232
std = []
3333
default = ["std"]
34-
35-
[[test]]
36-
name = "compiletest"
37-
# Merely to avoid spraying cfg(error_in_core)
38-
required-features = ["std"]

impl/src/expand.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn fallback(input: &DeriveInput, error: syn::Error) -> TokenStream {
3636
#error
3737

3838
#[allow(unused_qualifications)]
39-
impl #impl_generics ::thiserror::__private::error::Error for #ty #ty_generics #where_clause
39+
impl #impl_generics ::core::error::Error for #ty #ty_generics #where_clause
4040
where
4141
// Work around trivial bounds being unstable.
4242
// https://github.com/rust-lang/rust/issues/48214
@@ -60,19 +60,17 @@ fn impl_struct(input: Struct) -> TokenStream {
6060
let source_body = if let Some(transparent_attr) = &input.attrs.transparent {
6161
let only_field = &input.fields[0];
6262
if only_field.contains_generic {
63-
error_inferred_bounds
64-
.insert(only_field.ty, quote!(::thiserror::__private::error::Error));
63+
error_inferred_bounds.insert(only_field.ty, quote!(::core::error::Error));
6564
}
6665
let member = &only_field.member;
6766
Some(quote_spanned! {transparent_attr.span=>
68-
::thiserror::__private::error::Error::source(self.#member.as_dyn_error())
67+
::core::error::Error::source(self.#member.as_dyn_error())
6968
})
7069
} else if let Some(source_field) = input.source_field() {
7170
let source = &source_field.member;
7271
if source_field.contains_generic {
7372
let ty = unoptional_type(source_field.ty);
74-
error_inferred_bounds
75-
.insert(ty, quote!(::thiserror::__private::error::Error + 'static));
73+
error_inferred_bounds.insert(ty, quote!(::core::error::Error + 'static));
7674
}
7775
let asref = if type_is_option(source_field.ty) {
7876
Some(quote_spanned!(source.member_span()=> .as_ref()?))
@@ -90,7 +88,7 @@ fn impl_struct(input: Struct) -> TokenStream {
9088
};
9189
let source_method = source_body.map(|body| {
9290
quote! {
93-
fn source(&self) -> ::core::option::Option<&(dyn ::thiserror::__private::error::Error + 'static)> {
91+
fn source(&self) -> ::core::option::Option<&(dyn ::core::error::Error + 'static)> {
9492
use thiserror::__private::AsDynError as _;
9593
#body
9694
}
@@ -143,7 +141,7 @@ fn impl_struct(input: Struct) -> TokenStream {
143141
}
144142
};
145143
quote! {
146-
fn provide<'_request>(&'_request self, #request: &mut std::error::Request<'_request>) {
144+
fn provide<'_request>(&'_request self, #request: &mut ::core::error::Request<'_request>) {
147145
#body
148146
}
149147
}
@@ -213,7 +211,7 @@ fn impl_struct(input: Struct) -> TokenStream {
213211

214212
quote! {
215213
#[allow(unused_qualifications)]
216-
impl #impl_generics ::thiserror::__private::error::Error for #ty #ty_generics #error_where_clause {
214+
impl #impl_generics ::core::error::Error for #ty #ty_generics #error_where_clause {
217215
#source_method
218216
#provide_method
219217
}
@@ -233,11 +231,11 @@ fn impl_enum(input: Enum) -> TokenStream {
233231
if let Some(transparent_attr) = &variant.attrs.transparent {
234232
let only_field = &variant.fields[0];
235233
if only_field.contains_generic {
236-
error_inferred_bounds.insert(only_field.ty, quote!(::thiserror::__private::error::Error));
234+
error_inferred_bounds.insert(only_field.ty, quote!(::core::error::Error));
237235
}
238236
let member = &only_field.member;
239237
let source = quote_spanned! {transparent_attr.span=>
240-
::thiserror::__private::error::Error::source(transparent.as_dyn_error())
238+
::core::error::Error::source(transparent.as_dyn_error())
241239
};
242240
quote! {
243241
#ty::#ident {#member: transparent} => #source,
@@ -246,7 +244,7 @@ fn impl_enum(input: Enum) -> TokenStream {
246244
let source = &source_field.member;
247245
if source_field.contains_generic {
248246
let ty = unoptional_type(source_field.ty);
249-
error_inferred_bounds.insert(ty, quote!(::thiserror::__private::error::Error + 'static));
247+
error_inferred_bounds.insert(ty, quote!(::core::error::Error + 'static));
250248
}
251249
let asref = if type_is_option(source_field.ty) {
252250
Some(quote_spanned!(source.member_span()=> .as_ref()?))
@@ -267,7 +265,7 @@ fn impl_enum(input: Enum) -> TokenStream {
267265
}
268266
});
269267
Some(quote! {
270-
fn source(&self) -> ::core::option::Option<&(dyn std::error::Error + 'static)> {
268+
fn source(&self) -> ::core::option::Option<&(dyn ::core::error::Error + 'static)> {
271269
use thiserror::__private::AsDynError as _;
272270
#[allow(deprecated)]
273271
match self {
@@ -372,7 +370,7 @@ fn impl_enum(input: Enum) -> TokenStream {
372370
}
373371
});
374372
Some(quote! {
375-
fn provide<'_request>(&'_request self, #request: &mut std::error::Request<'_request>) {
373+
fn provide<'_request>(&'_request self, #request: &mut ::core::error::Request<'_request>) {
376374
#[allow(deprecated)]
377375
match self {
378376
#(#arms)*
@@ -469,7 +467,7 @@ fn impl_enum(input: Enum) -> TokenStream {
469467

470468
quote! {
471469
#[allow(unused_qualifications)]
472-
impl #impl_generics ::thiserror::__private::error::Error for #ty #ty_generics #error_where_clause {
470+
impl #impl_generics ::core::error::Error for #ty #ty_generics #error_where_clause {
473471
#source_method
474472
#provide_method
475473
}

src/aserror.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::__private::error::Error;
1+
use core::error::Error;
22
use core::panic::UnwindSafe;
33

44
#[doc(hidden)]

src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,7 @@
236236
clippy::wildcard_imports
237237
)]
238238
#![cfg_attr(error_generic_member_access, feature(error_generic_member_access))]
239-
#![cfg_attr(
240-
not(feature = "std"),
241-
no_std,
242-
feature(error_in_core),
243-
doc(test(attr(feature(error_in_core))))
244-
)]
239+
#![cfg_attr(not(feature = "std"), no_std)]
245240

246241
#[cfg(all(thiserror_nightly_testing, not(error_generic_member_access)))]
247242
compile_error!("Build script probe failed to compile.");
@@ -263,10 +258,4 @@ pub mod __private {
263258
#[cfg(error_generic_member_access)]
264259
#[doc(hidden)]
265260
pub use crate::provide::ThiserrorProvide;
266-
#[cfg(not(feature = "std"))]
267-
#[doc(hidden)]
268-
pub use core::error;
269-
#[cfg(feature = "std")]
270-
#[doc(hidden)]
271-
pub use std::error;
272261
}

src/provide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::__private::error::{Error, Request};
1+
use core::error::{Error, Request};
22

33
#[doc(hidden)]
44
pub trait ThiserrorProvide: Sealed {

tests/test_backtrace.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(not(feature = "std"), feature(error_in_core))]
21
#![cfg_attr(thiserror_nightly_testing, feature(error_generic_member_access))]
32

43
use thiserror::Error;

tests/test_deprecated.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(not(feature = "std"), feature(error_in_core))]
21
#![deny(deprecated, clippy::all, clippy::pedantic)]
32

43
use thiserror::Error;

tests/test_display.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(not(feature = "std"), feature(error_in_core))]
21
#![allow(clippy::needless_raw_string_hashes, clippy::uninlined_format_args)]
32

43
use core::fmt::{self, Display};

tests/test_error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(not(feature = "std"), feature(error_in_core))]
21
#![allow(dead_code)]
32

43
use core::fmt::{self, Display};

tests/test_expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(not(feature = "std"), feature(error_in_core))]
21
#![allow(clippy::iter_cloned_collect, clippy::uninlined_format_args)]
32

43
use core::fmt::Display;

0 commit comments

Comments
 (0)