Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to stabilized const_fn_trait_bound #797

Merged
merged 1 commit into from Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
17 changes: 17 additions & 0 deletions crossbeam-epoch/build.rs
Expand Up @@ -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
Expand All @@ -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");
}
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