forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum_cast.rs
93 lines (75 loc) · 1.41 KB
/
enum_cast.rs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// skip-filecheck
// EMIT_MIR enum_cast.foo.built.after.mir
// EMIT_MIR enum_cast.bar.built.after.mir
// EMIT_MIR enum_cast.boo.built.after.mir
// EMIT_MIR enum_cast.far.built.after.mir
enum Foo {
A
}
enum Bar {
A, B
}
#[repr(u8)]
enum Boo {
A, B
}
#[repr(i16)]
enum Far {
A, B
}
fn foo(foo: Foo) -> usize {
foo as usize
}
fn bar(bar: Bar) -> usize {
bar as usize
}
fn boo(boo: Boo) -> usize {
boo as usize
}
fn far(far: Far) -> isize {
far as isize
}
// EMIT_MIR enum_cast.droppy.built.after.mir
enum Droppy {
A, B, C
}
impl Drop for Droppy {
fn drop(&mut self) {}
}
fn droppy() {
{
let x = Droppy::C;
// remove this entire test once `cenum_impl_drop_cast` becomes a hard error
#[allow(cenum_impl_drop_cast)]
let y = x as usize;
}
let z = Droppy::B;
}
#[repr(i16)]
enum SignedAroundZero {
A = -2,
B = 0,
C = 2,
}
#[repr(u16)]
enum UnsignedAroundZero {
A = 65535,
B = 0,
C = 1,
}
// EMIT_MIR enum_cast.signy.built.after.mir
fn signy(x: SignedAroundZero) -> i16 {
x as i16
}
// EMIT_MIR enum_cast.unsigny.built.after.mir
fn unsigny(x: UnsignedAroundZero) -> u16 {
// FIXME: This doesn't get an around-the-end range today, sadly.
x as u16
}
enum NotStartingAtZero { A = 4, B = 6, C = 8 }
// EMIT_MIR enum_cast.offsetty.built.after.mir
fn offsetty(x: NotStartingAtZero) -> u32 {
x as u32
}
fn main() {
}