rust/tests/fail/stacked_borrows/illegal_write3.rs

9 lines
355 B
Rust
Raw Normal View History

2018-10-19 11:38:23 -05:00
fn main() {
let target = 42;
// Make sure raw ptr with raw tag cannot mutate frozen location without breaking the shared ref.
let r#ref = ⌖ // freeze
let ptr = r#ref as *const _ as *mut _; // raw ptr, with raw tag
2022-07-13 17:59:33 -05:00
unsafe { *ptr = 42 }; //~ ERROR: /write access .* only grants SharedReadOnly permission/
let _val = *r#ref;
2018-10-19 11:38:23 -05:00
}