about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-10-16 08:06:56 +0000
committerbors <bors@rust-lang.org>2015-10-16 08:06:56 +0000
commit17776fdc73705f02404620e584237fd9d67a1cf1 (patch)
treeb7bd6d0a6c34f905b37fe8b5d6f329e4d4c7c3e2
parente4c7bb9ea76eb75fee5365a1eb3c399f2ea7b393 (diff)
parent128ded71100f02026fd03a4c13e1333cd633cac9 (diff)
downloadrust-17776fdc73705f02404620e584237fd9d67a1cf1.tar.gz
rust-17776fdc73705f02404620e584237fd9d67a1cf1.zip
Auto merge of #29085 - petrochenkov:nonzero, r=alexcrichton
-rw-r--r--src/libcore/nonzero.rs30
1 files changed, 24 insertions, 6 deletions
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: 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> {