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