]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/double_check2.rs
Auto merge of #81132 - bugadani:map-prealloc, r=matthewjasper
[rust.git] / src / test / ui / consts / const-eval / double_check2.rs
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
7 enum Foo {
8     A = 5,
9     B = 42,
10 }
11 enum Bar {
12     C = 42,
13     D = 99,
14 }
15 #[repr(C)]
16 union Union {
17     foo: &'static Foo,
18     bar: &'static Bar,
19     u8: &'static u8,
20 }
21 static BAR: u8 = 5;
22 static FOO: (&Foo, &Bar) = unsafe {
23     (
24         // undefined behavior
25         Union { u8: &BAR }.foo,
26         Union { u8: &BAR }.bar,
27     )
28 };
29 static FOO2: (&Foo, &Bar) = unsafe { (std::mem::transmute(&BAR), std::mem::transmute(&BAR)) };
30 //^ undefined behavior
31
32 fn main() {}