about summary refs log tree commit diff
diff options
context:
space:
mode:
authordylan_DPC <dylan.dpc@gmail.com>2018-12-28 16:58:55 +0530
committerdylan_DPC <dylan.dpc@gmail.com>2018-12-28 16:58:55 +0530
commitd11a58b6769105082a06a185660ae7cbd6dfc173 (patch)
tree41a8b1c0b7d60a6e508207c0fe591ac1bc4fc6a3
parentee49bf8964492ad22f530cbcadcafc6704ec44c3 (diff)
downloadrust-d11a58b6769105082a06a185660ae7cbd6dfc173.tar.gz
rust-d11a58b6769105082a06a185660ae7cbd6dfc173.zip
Make the getter for NonZero types into a const fn
-rw-r--r--src/libcore/num/mod.rs2
-rw-r--r--src/test/ui/consts/const-nonzero.rs9
2 files changed, 10 insertions, 1 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index e776513770e..97bf582df5a 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -77,7 +77,7 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st
                 /// Returns the value as a primitive type.
                 #[stable(feature = "nonzero", since = "1.28.0")]
                 #[inline]
-                pub fn get(self) -> $Int {
+                pub const fn get(self) -> $Int {
                     self.0
                 }
 
diff --git a/src/test/ui/consts/const-nonzero.rs b/src/test/ui/consts/const-nonzero.rs
new file mode 100644
index 00000000000..02900924c13
--- /dev/null
+++ b/src/test/ui/consts/const-nonzero.rs
@@ -0,0 +1,9 @@
+// compile-pass
+
+use std::num::NonZeroU8;
+
+const X: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
+const Y: u8 = X.get();
+
+fn main() {
+}
\ No newline at end of file