Skip to content

Commit 0755c41

Browse files
Test NonZeroU8::new in a const context
1 parent 0b20ce9 commit 0755c41

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/test/ui/consts/const-nonzero.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
// build-pass (FIXME(62277): could be check-pass?)
1+
// run-pass
2+
3+
#![feature(const_nonzero_int_methods)]
24

35
use std::num::NonZeroU8;
46

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

10+
const ZERO: Option<NonZeroU8> = NonZeroU8::new(0);
11+
const ONE: Option<NonZeroU8> = NonZeroU8::new(1);
12+
813
fn main() {
14+
assert_eq!(Y, 5);
15+
16+
assert!(ZERO.is_none());
17+
assert_eq!(ONE.unwrap().get(), 1);
918
}

0 commit comments

Comments
 (0)