summaryrefslogtreecommitdiffstats
path: root/tests/ui/enum-discriminant/repr128.rs
blob: 00021a07b371952b37707df2dd6fa069d48561e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// run-pass
#![feature(repr128, core_intrinsics, discriminant_kind)]
//~^ WARN the feature `repr128` is incomplete

use std::intrinsics::discriminant_value;
use std::marker::DiscriminantKind;

#[repr(i128)]
enum Signed {
    Zero = 0,
    Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f,
    U64Limit = u64::MAX as i128 + 1,
    SmallNegative = -1,
    BigNegative = i128::MIN,
    Next,
}

#[repr(u128)]
enum Unsigned {
    Zero = 0,
    Staircase = 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f,
    U64Limit = u64::MAX as u128 + 1,
    Next,
}

fn discr<T, U>(v: T, value: U)
where
    <T as DiscriminantKind>::Discriminant: PartialEq<U>,
{
    assert!(discriminant_value(&v) == value);
}

fn main() {
    discr(Signed::Zero, 0);
    discr(Signed::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f);
    discr(Signed::U64Limit, u64::MAX as i128 + 1);
    discr(Signed::SmallNegative, -1);
    discr(Signed::BigNegative, i128::MIN);
    discr(Signed::Next, i128::MIN + 1);

    discr(Unsigned::Zero, 0);
    discr(Unsigned::Staircase, 0x01_02_03_04_05_06_07_08_09_0a_0b_0c_0d_0e_0f);
    discr(Unsigned::U64Limit, u64::MAX as u128 + 1);
    discr(Unsigned::Next, u64::MAX as u128 + 2);
}