-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Soundness Hole: Aliasing and Mutating static references in safe Rust #50162
Comments
fn static_table() -> &'static mut [u8; 20] {
let ref mut table = [0; 20];
table
}
fn main() {
let table = static_table();
table[4] = 20;
println!("{:?}", table);
} The above returns different arrays of values depending on stable, beta, or release channel. Only in debug does |
Neither examples compile before 1.21.0. |
looks like #46557 |
It appears so. Enabling nll prevents it from compiling. |
Closing as it seems to be a duplicate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The text was updated successfully, but these errors were encountered: