summary refs log tree commit diff
path: root/src/test/ui/consts/const-nonzero.rs
blob: 2160bad48074dc9117ad9c1ddc2bea2f4a904eaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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);
}