Make the getter for NonZero types into a const fn
This commit is contained in:
parent
ee49bf8964
commit
d11a58b676
@ -77,7 +77,7 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st
|
|||||||
/// Returns the value as a primitive type.
|
/// Returns the value as a primitive type.
|
||||||
#[stable(feature = "nonzero", since = "1.28.0")]
|
#[stable(feature = "nonzero", since = "1.28.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get(self) -> $Int {
|
pub const fn get(self) -> $Int {
|
||||||
self.0
|
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…
Reference in New Issue
Block a user