Skip to content

Commit 7b2d65f

Browse files
committed
Update to stabilized const_fn_trait_bound
1 parent b11f1a8 commit 7b2d65f

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

crossbeam-epoch/Cargo.toml

+7-2
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,26 @@ std = ["alloc", "crossbeam-utils/std", "lazy_static"]
2727
# NOTE: Disabling both `std` *and* `alloc` features is not supported yet.
2828
alloc = []
2929

30+
# These features are no longer used.
31+
# TODO: remove in the next major version.
3032
# Enable to use of unstable functionality.
3133
# This is disabled by default and requires recent nightly compiler.
3234
#
3335
# NOTE: This feature is outside of the normal semver guarantees and minor or
3436
# patch versions of crossbeam may make breaking changes to them at any time.
35-
nightly = ["crossbeam-utils/nightly", "const_fn"]
37+
nightly = ["crossbeam-utils/nightly"]
3638

3739
# Enable the use of loom for concurrency testing.
3840
#
3941
# NOTE: This feature is outside of the normal semver guarantees and minor or
4042
# patch versions of crossbeam may make breaking changes to them at any time.
4143
loom = ["loom-crate", "crossbeam-utils/loom"]
4244

45+
[build-dependencies]
46+
autocfg = "1"
47+
4348
[dependencies]
4449
cfg-if = "1"
45-
const_fn = { version = "0.4.4", optional = true }
4650
memoffset = "0.6"
4751

4852
# Enable the use of loom for concurrency testing.
@@ -67,3 +71,4 @@ default-features = false
6771

6872
[dev-dependencies]
6973
rand = "0.8"
74+
rustversion = "1"

crossbeam-epoch/build.rs

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ fn main() {
2929
}
3030
};
3131

32+
let cfg = match autocfg::AutoCfg::new() {
33+
Ok(cfg) => cfg,
34+
Err(e) => {
35+
println!(
36+
"cargo:warning={}: unable to determine rustc version: {}",
37+
env!("CARGO_PKG_NAME"),
38+
e
39+
);
40+
return;
41+
}
42+
};
43+
3244
// Note that this is `no_*`, not `has_*`. This allows treating
3345
// `cfg(target_has_atomic = "ptr")` as true when the build script doesn't
3446
// run. This is needed for compatibility with non-cargo build systems that
@@ -37,5 +49,10 @@ fn main() {
3749
println!("cargo:rustc-cfg=crossbeam_no_atomic_cas");
3850
}
3951

52+
if cfg.probe_rustc_version(1, 61) {
53+
// TODO: invert cfg once Rust 1.61 became stable.
54+
println!("cargo:rustc-cfg=crossbeam_const_fn_trait_bound");
55+
}
56+
4057
println!("cargo:rerun-if-changed=no_atomic.rs");
4158
}

crossbeam-epoch/src/atomic.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,16 @@ impl<T: ?Sized + Pointable> Atomic<T> {
342342
///
343343
/// let a = Atomic::<i32>::null();
344344
/// ```
345-
///
346-
#[cfg_attr(all(feature = "nightly", not(crossbeam_loom)), const_fn::const_fn)]
345+
#[cfg(all(crossbeam_const_fn_trait_bound, not(crossbeam_loom)))]
346+
pub const fn null() -> Atomic<T> {
347+
Self {
348+
data: AtomicUsize::new(0),
349+
_marker: PhantomData,
350+
}
351+
}
352+
353+
/// Returns a new null atomic pointer.
354+
#[cfg(not(all(crossbeam_const_fn_trait_bound, not(crossbeam_loom))))]
347355
pub fn null() -> Atomic<T> {
348356
Self {
349357
data: AtomicUsize::new(0),
@@ -1594,7 +1602,7 @@ mod tests {
15941602
Shared::<i64>::null().with_tag(7);
15951603
}
15961604

1597-
#[cfg(feature = "nightly")]
1605+
#[rustversion::since(1.61)]
15981606
#[test]
15991607
fn const_atomic_null() {
16001608
use super::Atomic;

crossbeam-epoch/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
unreachable_pub
6363
)]
6464
#![cfg_attr(not(feature = "std"), no_std)]
65-
#![cfg_attr(feature = "nightly", feature(const_fn_trait_bound))]
6665

6766
#[cfg(crossbeam_loom)]
6867
extern crate loom_crate as loom;

0 commit comments

Comments
 (0)