2019-02-10 14:59:13 +01:00
|
|
|
//@ compile-flags: -Zunleash-the-miri-inside-of-you
|
|
|
|
|
|
|
|
|
|
use std::cell::UnsafeCell;
|
|
|
|
|
|
|
|
|
|
// a test demonstrating what things we could allow with a smarter const qualification
|
|
|
|
|
|
|
|
|
|
static FOO: &&mut u32 = &&mut 42;
|
2024-02-14 12:28:07 +00:00
|
|
|
//~^ ERROR encountered mutable pointer in final value of static
|
2019-02-10 14:59:13 +01:00
|
|
|
|
|
|
|
|
static BAR: &mut () = &mut ();
|
2024-02-14 12:28:07 +00:00
|
|
|
//~^ ERROR encountered mutable pointer in final value of static
|
2019-02-10 14:59:13 +01:00
|
|
|
|
|
|
|
|
struct Foo<T>(T);
|
|
|
|
|
|
|
|
|
|
static BOO: &mut Foo<()> = &mut Foo(());
|
2024-02-14 12:28:07 +00:00
|
|
|
//~^ ERROR encountered mutable pointer in final value of static
|
2019-02-10 14:59:13 +01:00
|
|
|
|
|
|
|
|
struct Meh {
|
|
|
|
|
x: &'static UnsafeCell<i32>,
|
|
|
|
|
}
|
|
|
|
|
unsafe impl Sync for Meh {}
|
2024-02-14 12:28:07 +00:00
|
|
|
static MEH: Meh = Meh { x: &UnsafeCell::new(42) };
|
|
|
|
|
//~^ ERROR encountered mutable pointer in final value of static
|
2019-02-10 14:59:13 +01:00
|
|
|
|
|
|
|
|
static OH_YES: &mut i32 = &mut 42;
|
2024-02-14 12:28:07 +00:00
|
|
|
//~^ ERROR encountered mutable pointer in final value of static
|
2019-02-10 14:59:13 +01:00
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
unsafe {
|
2019-09-17 16:25:25 -07:00
|
|
|
*MEH.x.get() = 99;
|
2019-02-10 14:59:13 +01:00
|
|
|
}
|
|
|
|
|
*OH_YES = 99; //~ ERROR cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
|
|
|
|
|
}
|