rust/tests/fail/stacked_borrows/shr_frozen_violation1.rs

16 lines
298 B
Rust
Raw Normal View History

fn foo(x: &mut i32) -> i32 {
*x = 5;
unknown_code(&*x);
*x // must return 5
}
fn main() {
println!("{}", foo(&mut 0));
}
fn unknown_code(x: &i32) {
unsafe {
2022-07-13 17:59:33 -05:00
*(x as *const i32 as *mut i32) = 7; //~ ERROR: /write access .* only grants SharedReadOnly permission/
2022-06-21 13:40:02 -05:00
}
}