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
46
47
48
49
50
51
52
53
54
|
// run-pass
#![feature(core_intrinsics, repr128)]
//~^ WARN the feature `repr128` is incomplete
use std::intrinsics::discriminant_value;
enum E1 {
A,
B,
}
#[repr(i8)]
enum E2 {
A = 7,
B = -2,
}
#[repr(C)]
enum E3 {
A = 42,
B = 100,
}
#[repr(i128)]
enum E4 {
A = 0x1223_3445_5667_7889,
B = -0x1223_3445_5667_7889,
}
fn main() {
let mut target: [isize; 3] = [0, 0, 0];
target[1] = discriminant_value(&E1::A);
assert_eq!(target, [0, 0, 0]);
target[1] = discriminant_value(&E1::B);
assert_eq!(target, [0, 1, 0]);
let mut target: [i8; 3] = [0, 0, 0];
target[1] = discriminant_value(&E2::A);
assert_eq!(target, [0, 7, 0]);
target[1] = discriminant_value(&E2::B);
assert_eq!(target, [0, -2, 0]);
let mut target: [isize; 3] = [0, 0, 0];
target[1] = discriminant_value(&E3::A);
assert_eq!(target, [0, 42, 0]);
target[1] = discriminant_value(&E3::B);
assert_eq!(target, [0, 100, 0]);
let mut target: [i128; 3] = [0, 0, 0];
target[1] = discriminant_value(&E4::A);
assert_eq!(target, [0, 0x1223_3445_5667_7889, 0]);
target[1] = discriminant_value(&E4::B);
assert_eq!(target, [0, -0x1223_3445_5667_7889, 0]);
}
|