Skip to content

Commit f2d3b4b

Browse files
committed
more explicitly explain the UB around immutable extern statics
1 parent 1bf2cdc commit f2d3b4b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/behavior-considered-undefined.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Please read the [Rustonomicon] before writing unsafe code.
5050
types are passed in a (nested) field of a compound type, but not behind
5151
pointer indirections.
5252
* Mutating immutable bytes. All bytes inside a [`const`] item are immutable.
53-
The bytes owned by an immutable binding are immutable, unless those bytes are part of an [`UnsafeCell<U>`].
53+
The bytes owned by an immutable binding or immutable `static` are immutable, unless those bytes are part of an [`UnsafeCell<U>`].
5454

5555
Moreover, the bytes [pointed to] by a shared reference, including transitively through other references (both shared and mutable) and `Box`es, are immutable; transitivity includes those references stored in fields of compound types.
5656

src/items/external-blocks.md

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ of initializing the static.
5656
Extern statics can be either immutable or mutable just like [statics] outside of external blocks.
5757
An immutable static *must* be initialized before any Rust code is executed. It is not enough for
5858
the static to be initialized before Rust code reads from it.
59+
One Rust code runs, mutating an immutable static (from inside or outside Rust) is UB,
60+
except if the mutation happens inside an `UnsafeCell`.
5961

6062
## ABI
6163

0 commit comments

Comments
 (0)