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
This commit is contained in:
commit
3cda631ea4
@ -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
|
||||
}
|
||||
|
||||
|
9
src/test/ui/consts/const-nonzero.rs
Normal file
9
src/test/ui/consts/const-nonzero.rs
Normal file
@ -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() {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user