diff --git a/src/libcore/nonzero.rs b/src/libcore/nonzero.rs index c945e4e0661..2cf8bad60cd 100644 --- a/src/libcore/nonzero.rs +++ b/src/libcore/nonzero.rs @@ -38,13 +38,31 @@ unsafe impl Zeroable for u64 {} #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)] pub struct NonZero(T); +#[cfg(stage0)] +macro_rules! nonzero_new { + () => ( + /// Creates an instance of NonZero with the provided value. + /// You must indeed ensure that the value is actually "non-zero". + #[inline(always)] + pub unsafe fn new(inner: T) -> NonZero { + NonZero(inner) + } + ) +} +#[cfg(not(stage0))] +macro_rules! nonzero_new { + () => ( + /// Creates an instance of NonZero with the provided value. + /// You must indeed ensure that the value is actually "non-zero". + #[inline(always)] + pub unsafe const fn new(inner: T) -> NonZero { + NonZero(inner) + } + ) +} + impl NonZero { - /// Creates an instance of NonZero with the provided value. - /// You must indeed ensure that the value is actually "non-zero". - #[inline(always)] - pub unsafe fn new(inner: T) -> NonZero { - NonZero(inner) - } + nonzero_new!{} } impl Deref for NonZero {