Disallow reference to static mut
for expressions
Add `E0796` error code. Add `static_mut_ref` lint. This is the idea for the 2024 edition.
This commit is contained in:
parent
595bc6f003
commit
2c088f9520
9 changed files with 261 additions and 0 deletions
|
@ -515,6 +515,7 @@ E0792: include_str!("./error_codes/E0792.md"),
|
|||
E0793: include_str!("./error_codes/E0793.md"),
|
||||
E0794: include_str!("./error_codes/E0794.md"),
|
||||
E0795: include_str!("./error_codes/E0795.md"),
|
||||
E0796: include_str!("./error_codes/E0796.md"),
|
||||
}
|
||||
|
||||
// Undocumented removed error codes. Note that many removed error codes are kept in the list above
|
||||
|
|
22
compiler/rustc_error_codes/src/error_codes/E0796.md
Normal file
22
compiler/rustc_error_codes/src/error_codes/E0796.md
Normal file
|
@ -0,0 +1,22 @@
|
|||
Reference of mutable static.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,edition2024,E0796
|
||||
static mut X: i32 = 23;
|
||||
static mut Y: i32 = 24;
|
||||
|
||||
unsafe {
|
||||
let y = &X;
|
||||
let ref x = X;
|
||||
let (x, y) = (&X, &Y);
|
||||
foo(&X);
|
||||
}
|
||||
|
||||
fn foo<'a>(_x: &'a i32) {}
|
||||
```
|
||||
|
||||
Mutable statics can be written to by multiple threads: aliasing violations or
|
||||
data races will cause undefined behavior.
|
||||
|
||||
Reference of mutable static is a hard error from 2024 edition.
|
Loading…
Add table
Add a link
Reference in a new issue