Skip to content

Commit 3cda631

Browse files
committed
Auto merge of #57167 - Dylan-DPC:feature/non-zero-getters, r=SimonSapin
Make the getter for NonZero types into a const fn Closes #53331 Rework of #56739 cc @Lokathor r? @oli-obk
2 parents 48742c6 + 39f95fa commit 3cda631

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/libcore/num/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st
7777
/// Returns the value as a primitive type.
7878
#[stable(feature = "nonzero", since = "1.28.0")]
7979
#[inline]
80-
pub fn get(self) -> $Int {
80+
pub const fn get(self) -> $Int {
8181
self.0
8282
}
8383

src/test/ui/consts/const-nonzero.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-pass
2+
3+
use std::num::NonZeroU8;
4+
5+
const X: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
6+
const Y: u8 = X.get();
7+
8+
fn main() {
9+
}

0 commit comments

Comments
 (0)