diff --git a/crossbeam-epoch/src/atomic.rs b/crossbeam-epoch/src/atomic.rs index 0da07c752..ac1e68584 100644 --- a/crossbeam-epoch/src/atomic.rs +++ b/crossbeam-epoch/src/atomic.rs @@ -309,6 +309,47 @@ impl Atomic { pub fn new(init: T) -> Atomic { Self::init(init) } + + /// Returns a new null atomic pointer. + /// + /// This allows creating a null atomic pointer in a constant context on stable Rust. + /// + /// # Examples + /// + /// ``` + /// use crossbeam_epoch::Atomic; + /// + /// static A: Atomic = Atomic::::const_null(); + /// ``` + #[cfg(not(crossbeam_loom))] + pub const fn const_null() -> Self { + Self { + data: AtomicUsize::new(0), + _marker: PhantomData, + } + } +} + +impl Atomic<[MaybeUninit]> { + /// Returns a new null atomic pointer. + /// + /// This allows creating a null atomic pointer in a constant context on stable Rust. + /// + /// # Examples + /// + /// ``` + /// use crossbeam_epoch::Atomic; + /// use std::mem::MaybeUninit; + /// + /// static A: Atomic<[MaybeUninit]> = Atomic::<[MaybeUninit<_>]>::const_null(); + /// ``` + #[cfg(not(crossbeam_loom))] + pub const fn const_null() -> Self { + Self { + data: AtomicUsize::new(0), + _marker: PhantomData, + } + } } impl Atomic { @@ -342,7 +383,6 @@ impl Atomic { /// /// let a = Atomic::::null(); /// ``` - /// #[cfg_attr(all(feature = "nightly", not(crossbeam_loom)), const_fn::const_fn)] pub fn null() -> Atomic { Self { @@ -1589,7 +1629,7 @@ impl Default for Shared<'_, T> { #[cfg(all(test, not(crossbeam_loom)))] mod tests { - use super::{Owned, Shared}; + use super::{Atomic, Owned, Shared}; use std::mem::MaybeUninit; #[test] @@ -1602,11 +1642,10 @@ mod tests { Shared::::null().with_tag(7); } - #[cfg(feature = "nightly")] #[test] fn const_atomic_null() { - use super::Atomic; - static _U: Atomic = Atomic::::null(); + static _U1: Atomic = Atomic::::const_null(); + static _U2: Atomic<[MaybeUninit]> = Atomic::<[MaybeUninit<_>]>::const_null(); } #[test]