1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-18 20:39:35 +02:00

Update mutable-static-variables.md (#1331)

From a discussion in #1297.
This commit is contained in:
Martin Geisler 2023-10-09 15:15:26 +02:00 committed by GitHub
parent 65f6dbcd85
commit 7bffb7f2c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,7 +29,11 @@ fn main() {
<details>
Using a mutable static is generally a bad idea, but there are some cases where it might make sense
in low-level `no_std` code, such as implementing a heap allocator or working with some C APIs.
- The program here is safe because it is single-threaded. However, the Rust compiler is conservative
and will assume the worst. Try removing the `unsafe` and see how the compiler explains that it is
undefined behavior to mutate a static from multiple threads.
- Using a mutable static is generally a bad idea, but there are some cases where it might make sense
in low-level `no_std` code, such as implementing a heap allocator or working with some C APIs.
</details>