Skip to content

Commit

Permalink
Make const_fn crate optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Dec 9, 2020
1 parent 207b96a commit 5cc4cfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crossbeam-epoch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 9 additions & 4 deletions crossbeam-epoch/src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -327,8 +326,8 @@ impl<T: ?Sized + Pointable> Atomic<T> {
/// let a = Atomic::<i32>::null();
/// ```
///
#[const_fn(feature = "nightly")]
pub const fn null() -> Atomic<T> {
#[cfg_attr(feature = "nightly", const_fn::const_fn)]
pub fn null() -> Atomic<T> {
Self {
data: AtomicUsize::new(0),
_marker: PhantomData,
Expand Down Expand Up @@ -1360,7 +1359,7 @@ impl<T: ?Sized + Pointable> Default for Shared<'_, T> {

#[cfg(test)]
mod tests {
use super::Shared;
use super::{Atomic, Shared};

#[test]
fn valid_tag_i8() {
Expand All @@ -1371,4 +1370,10 @@ mod tests {
fn valid_tag_i64() {
Shared::<i64>::null().with_tag(7);
}

#[cfg(feature = "nightly")]
#[test]
fn const_atomic_null() {
const _: Atomic<u8> = Atomic::<u8>::null();
}
}

0 comments on commit 5cc4cfe

Please sign in to comment.