Closed
Description
fn static_val() -> &'static mut u8 {
let ref mut x = 0;
x
}
fn main() {
let ref1 = static_val();
let ref2 = static_val();
*ref1 = 20;
*ref2 = 32;
println!("{}", ref1);
}
The variable x is a mutable reference to a u8 that is promoted to a &'static mut u8. By calling that function multiple times, you can alias the mutable reference in safe Rust.
Metadata
Metadata
Assignees
Labels
No labels