From cb689be312fcbb416c7fb606be0ab5c250bd4305 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Tue, 18 Jul 2023 07:23:03 +0200 Subject: [PATCH] Static variables don't need unsafe (#995) --- src/basic-syntax/static-and-const.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/basic-syntax/static-and-const.md b/src/basic-syntax/static-and-const.md index 7af617cf..4b2273b6 100644 --- a/src/basic-syntax/static-and-const.md +++ b/src/basic-syntax/static-and-const.md @@ -41,9 +41,8 @@ fn main() { As noted in the [Rust RFC Book][1], these are not inlined upon use and have an actual associated memory location. This is useful for unsafe and embedded code, and the variable lives through the entirety of the program execution. When a globally-scoped value does not have a reason to need object identity, `const` is generally preferred. - +Because `static` variables are accessible from any thread, they need to be guarded, for example by a [`Mutex`](https://doc.rust-lang.org/std/sync/struct.Mutex.html), or accessed using `unsafe` code. We will look at [mutating static data](../unsafe/mutable-static-variables.md) in the chapter on Unsafe Rust. -Because `static` variables are accessible from any thread, mutable static variables require manual, unsafe, synchronization of accesses.