Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test NonZeroU8::new in a const context
  • Loading branch information
ecstatic-morse committed Feb 9, 2020
commit 0755c41ae26af20c940a80b3c1f686ab5916e655
11 changes: 10 additions & 1 deletion src/test/ui/consts/const-nonzero.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
// build-pass (FIXME(62277): could be check-pass?)
// run-pass

#![feature(const_nonzero_int_methods)]

use std::num::NonZeroU8;

const X: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
const Y: u8 = X.get();

const ZERO: Option<NonZeroU8> = NonZeroU8::new(0);
const ONE: Option<NonZeroU8> = NonZeroU8::new(1);

fn main() {
assert_eq!(Y, 5);

assert!(ZERO.is_none());
assert_eq!(ONE.unwrap().get(), 1);
}