about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-12-28 15:10:17 +0000
committerbors <bors@rust-lang.org>2018-12-28 15:10:17 +0000
commit3cda631ea45bac643ed9e4968f9292b0244a5b82 (patch)
tree272f92237cc79c8f65fb2b88d1a65064924edf8e /src
parent48742c68d9e53fba6b48c211140db595fbaa491e (diff)
parent39f95fa7c7541fe67f76579d10fad7e44328458d (diff)
downloadrust-3cda631ea45bac643ed9e4968f9292b0244a5b82.tar.gz
rust-3cda631ea45bac643ed9e4968f9292b0244a5b82.zip
Auto merge of #57167 - Dylan-DPC:feature/non-zero-getters, r=SimonSapin
Make the getter for NonZero types into a const fn

Closes https://github.com/rust-lang/rust/issues/53331

Rework of #56739

cc @Lokathor

r? @oli-obk
Diffstat (limited to 'src')
-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..c06ab227f64
--- /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() {
+}