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