Make the getter for NonZero types into a const fn

This commit is contained in:
dylan_DPC 2018-12-28 16:58:55 +05:30
parent ee49bf8964
commit d11a58b676
2 changed files with 10 additions and 1 deletions

View File

@ -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
}

View 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() {
}