]> git.proxmox.com Git - rustc.git/blame - src/test/ui/consts/const-eval/double_check2.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / test / ui / consts / const-eval / double_check2.rs
CommitLineData
1b1a35ee
XL
1// check-pass
2
3// This test exhibits undefined behavior, but it is very expensive and complex to check for such
4// UB in constants.
5// Thus, we do not detect it if you create references to statics in ways that are UB.
6
8faf50e0
XL
7enum Foo {
8 A = 5,
9 B = 42,
0531ce1d 10}
8faf50e0
XL
11enum Bar {
12 C = 42,
13 D = 99,
14}
e1599b0c 15#[repr(C)]
8faf50e0
XL
16union Union {
17 foo: &'static Foo,
18 bar: &'static Bar,
a1dfa0c6 19 u8: &'static u8,
8faf50e0 20}
a1dfa0c6 21static BAR: u8 = 5;
1b1a35ee
XL
22static FOO: (&Foo, &Bar) = unsafe {
23 (
24 // undefined behavior
25 Union { u8: &BAR }.foo,
26 Union { u8: &BAR }.bar,
27 )
28};
29static FOO2: (&Foo, &Bar) = unsafe { (std::mem::transmute(&BAR), std::mem::transmute(&BAR)) };
30//^ undefined behavior
0531ce1d 31
5bcae85e 32fn main() {}