rust/tests/compile-fail/static_memory_modification1.rs
2020-02-24 16:22:02 +01:00

13 lines
349 B
Rust

// Stacked Borrows detects that we are casting & to &mut and so it changes why we fail
// compile-flags: -Zmiri-disable-stacked-borrows
static X: usize = 5;
#[allow(mutable_transmutes)]
fn main() {
unsafe {
*std::mem::transmute::<&usize, &mut usize>(&X) = 6; //~ ERROR tried to modify constant memory
assert_eq!(X, 6);
}
}