Skip to content

Commit ce80c9f

Browse files
authored
Rollup merge of rust-lang#133145 - kornelski:static-mutex, r=traviscross
Document alternatives to `static mut` In rust-lang#133143 I've noticed alternatives to `static mut` aren't documented anywhere.
2 parents 86151ab + 15e6fc0 commit ce80c9f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

std/src/keyword_docs.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,9 @@ mod self_upper_keyword {}
14481448
/// in a multithreaded context. As such, all accesses to mutable `static`s
14491449
/// require an [`unsafe`] block.
14501450
///
1451+
/// When possible, it's often better to use a non-mutable `static` with an
1452+
/// interior mutable type such as [`Mutex`], [`OnceLock`], or an [atomic].
1453+
///
14511454
/// Despite their unsafety, mutable `static`s are necessary in many contexts:
14521455
/// they can be used to represent global state shared by the whole program or in
14531456
/// [`extern`] blocks to bind to variables from C libraries.
@@ -1468,7 +1471,10 @@ mod self_upper_keyword {}
14681471
/// [`extern`]: keyword.extern.html
14691472
/// [`mut`]: keyword.mut.html
14701473
/// [`unsafe`]: keyword.unsafe.html
1474+
/// [`Mutex`]: sync::Mutex
1475+
/// [`OnceLock`]: sync::OnceLock
14711476
/// [`RefCell`]: cell::RefCell
1477+
/// [atomic]: sync::atomic
14721478
/// [Reference]: ../reference/items/static-items.html
14731479
mod static_keyword {}
14741480

0 commit comments

Comments
 (0)