Skip to content

Commit 17776fd

Browse files
committedOct 16, 2015
Auto merge of #29085 - petrochenkov:nonzero, r=alexcrichton
2 parents e4c7bb9 + 128ded7 commit 17776fd

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed
 

‎src/libcore/nonzero.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,31 @@ unsafe impl Zeroable for u64 {}
3838
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)]
3939
pub struct NonZero<T: Zeroable>(T);
4040

41+
#[cfg(stage0)]
42+
macro_rules! nonzero_new {
43+
() => (
44+
/// Creates an instance of NonZero with the provided value.
45+
/// You must indeed ensure that the value is actually "non-zero".
46+
#[inline(always)]
47+
pub unsafe fn new(inner: T) -> NonZero<T> {
48+
NonZero(inner)
49+
}
50+
)
51+
}
52+
#[cfg(not(stage0))]
53+
macro_rules! nonzero_new {
54+
() => (
55+
/// Creates an instance of NonZero with the provided value.
56+
/// You must indeed ensure that the value is actually "non-zero".
57+
#[inline(always)]
58+
pub unsafe const fn new(inner: T) -> NonZero<T> {
59+
NonZero(inner)
60+
}
61+
)
62+
}
63+
4164
impl<T: Zeroable> NonZero<T> {
42-
/// Creates an instance of NonZero with the provided value.
43-
/// You must indeed ensure that the value is actually "non-zero".
44-
#[inline(always)]
45-
pub unsafe fn new(inner: T) -> NonZero<T> {
46-
NonZero(inner)
47-
}
65+
nonzero_new!{}
4866
}
4967

5068
impl<T: Zeroable> Deref for NonZero<T> {

0 commit comments

Comments
 (0)
Please sign in to comment.