2019-02-10 14:59:13 +01:00
|
|
|
//@ compile-flags: -Zunleash-the-miri-inside-of-you
|
2024-06-21 15:15:36 +10:00
|
|
|
//@ normalize-stderr-test: "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
|
|
|
|
|
//@ normalize-stderr-test: "([0-9a-f][0-9a-f] |╾─*ALLOC[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
|
2024-03-11 11:16:43 -04:00
|
|
|
|
2024-03-08 14:13:57 -05:00
|
|
|
#![deny(const_eval_mutable_ptr_in_final_value)]
|
2019-02-10 14:59:13 +01:00
|
|
|
use std::cell::UnsafeCell;
|
|
|
|
|
|
2024-03-26 09:46:30 +00:00
|
|
|
// This requires walking nested statics.
|
2019-02-10 14:59:13 +01:00
|
|
|
static FOO: &&mut u32 = &&mut 42;
|
2024-03-26 09:46:30 +00:00
|
|
|
//~^ ERROR it is undefined behavior to use this value
|
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
|
2024-03-08 14:13:57 -05:00
|
|
|
//~| WARNING this was previously accepted by the compiler
|
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
|
2024-03-08 14:13:57 -05:00
|
|
|
//~| WARNING this was previously accepted by the compiler
|
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) };
|
2024-03-26 09:46:30 +00:00
|
|
|
//~^ ERROR it is undefined behavior to use this value
|
2019-02-10 14:59:13 +01:00
|
|
|
|
|
|
|
|
static OH_YES: &mut i32 = &mut 42;
|
2024-03-26 09:46:30 +00:00
|
|
|
//~^ ERROR it is undefined behavior to use this value
|
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
|
|
|
|
|
}
|