Skip to content

Commit

Permalink
Auto merge of #57167 - Dylan-DPC:feature/non-zero-getters, r=SimonSapin
Browse files Browse the repository at this point in the history
Make the getter for NonZero types into a const fn

Closes #53331

Rework of #56739

cc @Lokathor

r? @oli-obk
  • Loading branch information
bors committed Dec 28, 2018
2 parents 48742c6 + 39f95fa commit 3cda631
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
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
@@ -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 3cda631

Please sign in to comment.