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)]
14 use std::mem::ManuallyDrop;
29 cell: ManuallyDrop<Cell<u32>>,
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 // FIXME the span here is wrong, sould be pointing at the line below, not above.
43 let _: &'static _ = &C;