rust/tests/compile-fail/modifying_constants.rs

10 lines
384 B
Rust
Raw Normal View History

// This should fail even without validation/SB
// compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
fn main() {
2017-02-07 13:28:54 -06:00
let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee
let y = unsafe { &mut *(x as *const i32 as *mut i32) };
2020-03-08 17:34:54 -05:00
*y = 42; //~ ERROR read-only
assert_eq!(*x, 42);
}