Skip to content

Commit

Permalink
Make the getter for NonZero types into a const fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan-DPC committed Dec 28, 2018
1 parent ee49bf8 commit d11a58b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/consts/const-nonzero.rs
Original file line number Diff line number Diff line change
@@ -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() {
}

0 comments on commit d11a58b

Please sign in to comment.