rust/tests/fail/static_memory_modification1.rs

13 lines
327 B
Rust
Raw Normal View History

// Stacked Borrows detects that we are casting & to &mut and so it changes why we fail
2022-07-08 11:08:32 -05:00
//@compile-flags: -Zmiri-disable-stacked-borrows
static X: usize = 5;
#[allow(mutable_transmutes)]
fn main() {
unsafe {
2020-03-08 17:34:54 -05:00
*std::mem::transmute::<&usize, &mut usize>(&X) = 6; //~ ERROR read-only
assert_eq!(X, 6);
}
}