diff --git a/portable-atomic-util/CHANGELOG.md b/portable-atomic-util/CHANGELOG.md index 6ede00e8..a8bc1cc1 100644 --- a/portable-atomic-util/CHANGELOG.md +++ b/portable-atomic-util/CHANGELOG.md @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [Unreleased] +- Support `impl Error for Arc` in no-std at Rust 1.81+. + ## [0.2.0] - 2024-05-07 - Rewrite `Arc` based on `std::sync::Arc`'s implementation. ([#142](https://github.com/taiki-e/portable-atomic/pull/142)) diff --git a/portable-atomic-util/build.rs b/portable-atomic-util/build.rs index 47c394ca..3868689a 100644 --- a/portable-atomic-util/build.rs +++ b/portable-atomic-util/build.rs @@ -33,7 +33,7 @@ fn main() { // Custom cfgs set by build script. Not public API. // grep -E 'cargo:rustc-cfg=' build.rs | grep -v '=//' | sed -E 's/^.*cargo:rustc-cfg=//; s/(=\\)?".*$//' | LC_ALL=C sort -u | tr '\n' ',' println!( - "cargo:rustc-check-cfg=cfg(portable_atomic_no_alloc,portable_atomic_no_alloc_layout_extras,portable_atomic_no_core_unwind_safe,portable_atomic_no_futures_api,portable_atomic_no_io_safety,portable_atomic_no_io_vec,portable_atomic_no_min_const_generics,portable_atomic_no_unsafe_op_in_unsafe_fn,portable_atomic_sanitize_thread)" + "cargo:rustc-check-cfg=cfg(portable_atomic_no_alloc,portable_atomic_no_alloc_layout_extras,portable_atomic_no_core_unwind_safe,portable_atomic_no_error_in_core,portable_atomic_no_futures_api,portable_atomic_no_io_safety,portable_atomic_no_io_vec,portable_atomic_no_min_const_generics,portable_atomic_no_unsafe_op_in_unsafe_fn,portable_atomic_sanitize_thread)" ); } @@ -72,6 +72,10 @@ fn main() { if !version.probe(63, 2022, 6, 15) { println!("cargo:rustc-cfg=portable_atomic_no_io_safety"); } + // error_in_core stabilized in Rust 1.81 (nightly-2024-06-09): https://github.com/rust-lang/rust/pull/125951 + if !version.probe(81, 2024, 6, 8) { + println!("cargo:rustc-cfg=portable_atomic_no_error_in_core"); + } if version.nightly { // `cfg(sanitize = "..")` is not stabilized. diff --git a/portable-atomic-util/src/arc.rs b/portable-atomic-util/src/arc.rs index 491cbac9..5d7da595 100644 --- a/portable-atomic-util/src/arc.rs +++ b/portable-atomic-util/src/arc.rs @@ -2405,18 +2405,22 @@ fn data_offset_align(align: usize) -> usize { layout.size() + padding_needed_for(layout, align) } -#[cfg(feature = "std")] -impl std::error::Error for Arc { +#[cfg(not(portable_atomic_no_error_in_core))] +use core::error; +#[cfg(all(portable_atomic_no_error_in_core, feature = "std"))] +use std::error; +#[cfg(any(not(portable_atomic_no_error_in_core), feature = "std"))] +impl error::Error for Arc { #[allow(deprecated)] fn description(&self) -> &str { - std::error::Error::description(&**self) + error::Error::description(&**self) } #[allow(deprecated)] - fn cause(&self) -> Option<&dyn std::error::Error> { - std::error::Error::cause(&**self) + fn cause(&self) -> Option<&dyn error::Error> { + error::Error::cause(&**self) } - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - std::error::Error::source(&**self) + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + error::Error::source(&**self) } }