1 // Check that constants with interior mutability inside unions are rejected
4 // Note that this test case relies on undefined behaviour to construct a
5 // constant with interior mutability that is "invisible" to the static checks.
6 // If for some reason this approach no longer works, it is should be fine to
7 // remove the test case.
10 // stderr-per-bitwidth
11 #![feature(const_mut_refs)]
12 #![feature(const_ptr_offset)]
13 #![feature(untagged_unions)]
33 let s = S { x: 0, y: E::A };
34 // Go through an &u32 reference which is definitely not allowed to mutate anything.
35 let p = &s.x as *const u32 as *mut u32;
36 // Change enum tag to E::B.
37 unsafe { *p.add(1) = 1 };
41 fn main() { //~ ERROR it is undefined behavior to use this value
42 let _: &'static _ = &C; //~ ERROR erroneous constant used
43 //~^ WARN this was previously accepted