summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2024-11-18 02:24:36 -0500
committerGitHub <noreply@github.com>2024-11-18 02:24:36 -0500
commit19c145d816fc03741dadc884765e90b256759108 (patch)
tree7af60de3bd59eb344d8efbfb939a95039da6f358 /library
parent72a8d536ef28ba6f7c185b905dbcefee7536fc72 (diff)
parent8b43a7ee5dc159dd24924150fd499e5961378113 (diff)
downloadrust-19c145d816fc03741dadc884765e90b256759108.tar.gz
rust-19c145d816fc03741dadc884765e90b256759108.zip
Rollup merge of #133145 - kornelski:static-mutex, r=traviscross
Document alternatives to `static mut`

In #133143 I've noticed alternatives to `static mut` aren't documented anywhere.
Diffstat (limited to 'library')
-rw-r--r--library/std/src/keyword_docs.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs
index 30d43c8bbfd..4302e24781e 100644
--- a/library/std/src/keyword_docs.rs
+++ b/library/std/src/keyword_docs.rs
@@ -1448,6 +1448,9 @@ mod self_upper_keyword {}
 /// in a multithreaded context. As such, all accesses to mutable `static`s
 /// require an [`unsafe`] block.
 ///
+/// When possible, it's often better to use a non-mutable `static` with an
+/// interior mutable type such as [`Mutex`], [`OnceLock`], or an [atomic].
+///
 /// Despite their unsafety, mutable `static`s are necessary in many contexts:
 /// they can be used to represent global state shared by the whole program or in
 /// [`extern`] blocks to bind to variables from C libraries.
@@ -1468,7 +1471,10 @@ mod self_upper_keyword {}
 /// [`extern`]: keyword.extern.html
 /// [`mut`]: keyword.mut.html
 /// [`unsafe`]: keyword.unsafe.html
+/// [`Mutex`]: sync::Mutex
+/// [`OnceLock`]: sync::OnceLock
 /// [`RefCell`]: cell::RefCell
+/// [atomic]: sync::atomic
 /// [Reference]: ../reference/items/static-items.html
 mod static_keyword {}