From 54b0581a7f95a4cf1a4dfbbb98c57594b160ff53 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Wed, 9 Dec 2020 21:51:25 +0900 Subject: [PATCH] Make const_fn crate optional dependency --- crossbeam-epoch/Cargo.toml | 4 ++-- crossbeam-epoch/src/atomic.rs | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crossbeam-epoch/Cargo.toml b/crossbeam-epoch/Cargo.toml index b56b6f52a..7a0c41b34 100644 --- a/crossbeam-epoch/Cargo.toml +++ b/crossbeam-epoch/Cargo.toml @@ -31,14 +31,14 @@ alloc = [] # This is disabled by default and requires recent nightly compiler. # Note that this is outside of the normal semver guarantees and minor versions # of crossbeam may make breaking changes to them at any time. -nightly = ["crossbeam-utils/nightly"] +nightly = ["crossbeam-utils/nightly", "const_fn"] # TODO: docs sanitize = [] # Makes it more likely to trigger any potential data races. [dependencies] cfg-if = "1" -const_fn = "0.4" +const_fn = { version = "0.4.4", optional = true } memoffset = "0.6" [dependencies.crossbeam-utils] diff --git a/crossbeam-epoch/src/atomic.rs b/crossbeam-epoch/src/atomic.rs index 517718745..fdcf604a3 100644 --- a/crossbeam-epoch/src/atomic.rs +++ b/crossbeam-epoch/src/atomic.rs @@ -10,7 +10,6 @@ use core::sync::atomic::{AtomicUsize, Ordering}; use crate::alloc::alloc; use crate::alloc::boxed::Box; use crate::guard::Guard; -use const_fn::const_fn; use crossbeam_utils::atomic::AtomicConsume; /// Given ordering for the success case in a compare-exchange operation, returns the strongest @@ -327,8 +326,8 @@ impl Atomic { /// let a = Atomic::::null(); /// ``` /// - #[const_fn(feature = "nightly")] - pub const fn null() -> Atomic { + #[cfg_attr(feature = "nightly", const_fn::const_fn)] + pub fn null() -> Atomic { Self { data: AtomicUsize::new(0), _marker: PhantomData, @@ -1371,4 +1370,11 @@ mod tests { fn valid_tag_i64() { Shared::::null().with_tag(7); } + + #[cfg(feature = "nightly")] + #[test] + fn const_atomic_null() { + use super::Atomic; + const _: Atomic = Atomic::::null(); + } }