-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow use of
static mut
inside unsafe block
```rust static mut X: i32 = 23; unsafe { let y = &X; } ``` This is the idea for the 2024 edition. Add `E0796` error code.
- Loading branch information
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Use of mutable static. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0796 | ||
static mut X: i32 = 23; | ||
unsafe { | ||
let y = &X; | ||
} | ||
unsafe fn foo() { | ||
static mut X: i32 = 1; | ||
let y = &X; | ||
} | ||
``` | ||
|
||
Mutable statics can be mutated by multiple threads: aliasing violations or | ||
data races will cause undefined behavior. | ||
|
||
Use of mutable static is a hard error from 2024 edition. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters