rust/tests/compile-fail/modifying_constants.rs
Ralf Jung e03255d625 fix existing tests
fix thread-local example to no longer write to pointers derived from a shared ref;
fix compile-fail test
2019-06-02 22:16:02 +02:00

10 lines
372 B
Rust

// This should fail even without validation
// compile-flags: -Zmiri-disable-validation
fn main() {
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) };
*y = 42; //~ ERROR tried to modify constant memory
assert_eq!(*x, 42);
}