Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/libcore/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,31 @@ unsafe impl Zeroable for u64 {}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
pub struct NonZero<T: Zeroable>(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<T> {
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<T> {
NonZero(inner)
}
)
}

impl<T: Zeroable> NonZero<T> {
/// 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<T> {
NonZero(inner)
}
nonzero_new!{}
}

impl<T: Zeroable> Deref for NonZero<T> {
Expand Down