rust/tests/fail/static_memory_modification2.rs

13 lines
341 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
use std::mem::transmute;
#[allow(mutable_transmutes)]
fn main() {
unsafe {
let s = "this is a test";
transmute::<&[u8], &mut [u8]>(s.as_bytes())[4] = 42; //~ ERROR: read-only
}
}