Skip to content

Commit 15e0f7d

Browse files
authored
Merge pull request #1502 from RalfJung/immutable-extern-static
more explicitly explain the UB around immutable extern statics
2 parents 301cc68 + 7c7feea commit 15e0f7d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/behavior-considered-undefined.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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+
Once Rust code runs, mutating an immutable static (from inside or outside Rust) is UB,
60+
except if the mutation happens to bytes inside of an `UnsafeCell`.
5961

6062
## ABI
6163

0 commit comments

Comments
 (0)