Disallow hidden references to mutable static

This commit is contained in:
Obei Sideg 2024-08-24 06:47:43 +03:00
parent d0985bb524
commit 74cab947f7
No known key found for this signature in database
GPG key ID: 14BF4B61362D0518
13 changed files with 203 additions and 133 deletions

View file

@ -1,14 +1,14 @@
#### Note: this error code is no longer emitted by the compiler.
You have created a reference to a mutable static.
Erroneous code example:
```compile_fail,edition2024,E0796
```
static mut X: i32 = 23;
fn work() {
let _val = unsafe { X };
}
let x_ref = unsafe { &mut X };
work();
// The next line has Undefined Behavior!

View file

@ -679,3 +679,4 @@ E0798: 0798,
// E0723, // unstable feature in `const` context
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
// E0744, // merged into E0728
// E0796, // unused error code. We use `static_mut_refs` lint instead.