1 // compile-flags: -Zunleash-the-miri-inside-of-you
5 use std::cell::UnsafeCell;
7 // this test ensures that our mutability story is sound
10 x: &'static UnsafeCell<i32>,
12 unsafe impl Sync for Meh {}
14 // the following will never be ok! no interior mut behind consts, because
15 // all allocs interned here will be marked immutable.
16 const MUH: Meh = Meh { //~ ERROR: it is undefined behavior to use this value
17 x: &UnsafeCell::new(42),
23 unsafe impl Sync for Synced {}
25 // Make sure we also catch this behind a type-erased `dyn Trait` reference.
26 const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) };
27 //~^ ERROR: it is undefined behavior to use this value
29 // Make sure we also catch mutable references.
30 const BLUNT: &mut i32 = &mut 42;
31 //~^ ERROR: mutable memory (`&mut`) is not allowed in constant