Rollup merge of #117556 - obeis:static-mut-ref-lint, r=davidtwco
Disallow reference to `static mut` and adding `static_mut_ref` lint Closes #114447 r? `@scottmcm`
This commit is contained in:
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.
|
||||
Reference in New Issue
Block a user