Skip to content

Commit

Permalink
Update to stabilized const_fn_trait_bound
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Mar 8, 2022
1 parent b11f1a8 commit 462d23b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
9 changes: 7 additions & 2 deletions crossbeam-epoch/Cargo.toml
Expand Up @@ -27,22 +27,26 @@ 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.
#
# 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.
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.
Expand All @@ -67,3 +71,4 @@ default-features = false

[dev-dependencies]
rand = "0.8"
rustversion = "1"
16 changes: 16 additions & 0 deletions crossbeam-epoch/build.rs
Expand Up @@ -29,6 +29,17 @@ fn main() {
}
};

let cfg = match autocfg::AutoCfg::new() {
Ok(cfg) => cfg,
Err(e) => {
println!(
"cargo:warning=crossbeam-utils: unable to determine rustc version: {}",
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
Expand All @@ -37,5 +48,10 @@ fn main() {
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
}

if cfg.probe_rustc_version(1, 61) {
// TODO: invert crossbeam_const_fn_trait_bound once Rust 1.61 became stable.
println!("cargo:rustc-cfg=crossbeam_const_fn_trait_bound");
}

println!("cargo:rerun-if-changed=no_atomic.rs");
}
14 changes: 11 additions & 3 deletions crossbeam-epoch/src/atomic.rs
Expand Up @@ -342,8 +342,16 @@ impl<T: ?Sized + Pointable> Atomic<T> {
///
/// let a = Atomic::<i32>::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<T> {
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<T> {
Self {
data: AtomicUsize::new(0),
Expand Down Expand Up @@ -1594,7 +1602,7 @@ mod tests {
Shared::<i64>::null().with_tag(7);
}

#[cfg(feature = "nightly")]
#[rustversion::since(1.61)]
#[test]
fn const_atomic_null() {
use super::Atomic;
Expand Down
1 change: 0 additions & 1 deletion crossbeam-epoch/src/lib.rs
Expand Up @@ -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;
Expand Down

0 comments on commit 462d23b

Please sign in to comment.