From 7b2d65fa21c9742c83f4a7e606418872405ad7d4 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 9 Mar 2022 12:41:15 +0900 Subject: [PATCH] Update to stabilized const_fn_trait_bound --- crossbeam-epoch/Cargo.toml | 9 +++++++-- crossbeam-epoch/build.rs | 17 +++++++++++++++++ crossbeam-epoch/src/atomic.rs | 14 +++++++++++--- crossbeam-epoch/src/lib.rs | 1 - 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/crossbeam-epoch/Cargo.toml b/crossbeam-epoch/Cargo.toml index bdb095ae1..a1c48ae28 100644 --- a/crossbeam-epoch/Cargo.toml +++ b/crossbeam-epoch/Cargo.toml @@ -27,12 +27,14 @@ std = ["alloc", "crossbeam-utils/std", "lazy_static"] # NOTE: Disabling both `std` *and* `alloc` features is not supported yet. alloc = [] +# These features are no longer used. +# TODO: remove in the next major version. # Enable to use of unstable functionality. # This is disabled by default and requires recent nightly compiler. # # NOTE: This feature is outside of the normal semver guarantees and minor or # patch versions of crossbeam may make breaking changes to them at any time. -nightly = ["crossbeam-utils/nightly", "const_fn"] +nightly = ["crossbeam-utils/nightly"] # Enable the use of loom for concurrency testing. # @@ -40,9 +42,11 @@ nightly = ["crossbeam-utils/nightly", "const_fn"] # patch versions of crossbeam may make breaking changes to them at any time. loom = ["loom-crate", "crossbeam-utils/loom"] +[build-dependencies] +autocfg = "1" + [dependencies] cfg-if = "1" -const_fn = { version = "0.4.4", optional = true } memoffset = "0.6" # Enable the use of loom for concurrency testing. @@ -67,3 +71,4 @@ default-features = false [dev-dependencies] rand = "0.8" +rustversion = "1" diff --git a/crossbeam-epoch/build.rs b/crossbeam-epoch/build.rs index 587e0580b..bba54d999 100644 --- a/crossbeam-epoch/build.rs +++ b/crossbeam-epoch/build.rs @@ -29,6 +29,18 @@ fn main() { } }; + let cfg = match autocfg::AutoCfg::new() { + Ok(cfg) => cfg, + Err(e) => { + println!( + "cargo:warning={}: unable to determine rustc version: {}", + env!("CARGO_PKG_NAME"), + e + ); + return; + } + }; + // Note that this is `no_*`, not `has_*`. This allows treating // `cfg(target_has_atomic = "ptr")` as true when the build script doesn't // run. This is needed for compatibility with non-cargo build systems that @@ -37,5 +49,10 @@ fn main() { println!("cargo:rustc-cfg=crossbeam_no_atomic_cas"); } + if cfg.probe_rustc_version(1, 61) { + // TODO: invert cfg once Rust 1.61 became stable. + println!("cargo:rustc-cfg=crossbeam_const_fn_trait_bound"); + } + println!("cargo:rerun-if-changed=no_atomic.rs"); } diff --git a/crossbeam-epoch/src/atomic.rs b/crossbeam-epoch/src/atomic.rs index f727387e6..b0b6a68e7 100644 --- a/crossbeam-epoch/src/atomic.rs +++ b/crossbeam-epoch/src/atomic.rs @@ -342,8 +342,16 @@ impl Atomic { /// /// let a = Atomic::::null(); /// ``` - /// - #[cfg_attr(all(feature = "nightly", not(crossbeam_loom)), const_fn::const_fn)] + #[cfg(all(crossbeam_const_fn_trait_bound, not(crossbeam_loom)))] + pub const fn null() -> Atomic { + Self { + data: AtomicUsize::new(0), + _marker: PhantomData, + } + } + + /// Returns a new null atomic pointer. + #[cfg(not(all(crossbeam_const_fn_trait_bound, not(crossbeam_loom))))] pub fn null() -> Atomic { Self { data: AtomicUsize::new(0), @@ -1594,7 +1602,7 @@ mod tests { Shared::::null().with_tag(7); } - #[cfg(feature = "nightly")] + #[rustversion::since(1.61)] #[test] fn const_atomic_null() { use super::Atomic; diff --git a/crossbeam-epoch/src/lib.rs b/crossbeam-epoch/src/lib.rs index 2791260d5..7150ec6f7 100644 --- a/crossbeam-epoch/src/lib.rs +++ b/crossbeam-epoch/src/lib.rs @@ -62,7 +62,6 @@ unreachable_pub )] #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(feature = "nightly", feature(const_fn_trait_bound))] #[cfg(crossbeam_loom)] extern crate loom_crate as loom;