2018-11-22 16:26:06 +01:00
|
|
|
fn foo(x: &mut i32) -> i32 {
|
2022-06-21 11:38:02 -07:00
|
|
|
*x = 5;
|
|
|
|
unknown_code(&*x);
|
|
|
|
*x // must return 5
|
2018-11-22 16:26:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("{}", foo(&mut 0));
|
|
|
|
}
|
|
|
|
|
2019-04-16 17:17:28 +02:00
|
|
|
fn unknown_code(x: &i32) {
|
2022-06-21 11:38:02 -07:00
|
|
|
unsafe {
|
2022-07-13 18:59:33 -04:00
|
|
|
*(x as *const i32 as *mut i32) = 7; //~ ERROR: /write access .* only grants SharedReadOnly permission/
|
2022-06-21 11:40:02 -07:00
|
|
|
}
|
2018-11-22 16:26:06 +01:00
|
|
|
}
|