rust/tests/compile-fail/static_memory_modification1.rs

13 lines
339 B
Rust
Raw Normal View History

// Validation detects that we are casting & to &mut and so it changes why we fail
// compile-flags: -Zmiri-disable-validation
static X: usize = 5;
#[allow(mutable_transmutes)]
fn main() {
unsafe {
2018-10-19 04:50:17 -05:00
*std::mem::transmute::<&usize, &mut usize>(&X) = 6; //~ ERROR tried to modify constant memory
assert_eq!(X, 6);
}
}