From d11a58b6769105082a06a185660ae7cbd6dfc173 Mon Sep 17 00:00:00 2001 From: dylan_DPC Date: Fri, 28 Dec 2018 16:58:55 +0530 Subject: [PATCH 1/2] Make the getter for NonZero types into a const fn --- src/libcore/num/mod.rs | 2 +- src/test/ui/consts/const-nonzero.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/const-nonzero.rs diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index e776513770ec6..97bf582df5a8c 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -77,7 +77,7 @@ assert_eq!(size_of::>(), 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 0000000000000..02900924c131e --- /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 From 39f95fa7c7541fe67f76579d10fad7e44328458d Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 28 Dec 2018 17:45:49 +0530 Subject: [PATCH 2/2] Update src/test/ui/consts/const-nonzero.rs Co-Authored-By: Dylan-DPC --- src/test/ui/consts/const-nonzero.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/consts/const-nonzero.rs b/src/test/ui/consts/const-nonzero.rs index 02900924c131e..c06ab227f6463 100644 --- a/src/test/ui/consts/const-nonzero.rs +++ b/src/test/ui/consts/const-nonzero.rs @@ -6,4 +6,4 @@ const X: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) }; const Y: u8 = X.get(); fn main() { -} \ No newline at end of file +}