Skip to content

Commit

Permalink
Merge pull request #1502 from RalfJung/immutable-extern-static
Browse files Browse the repository at this point in the history
more explicitly explain the UB around immutable extern statics
  • Loading branch information
traviscross authored Jul 3, 2024
2 parents 301cc68 + 7c7feea commit 15e0f7d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/behavior-considered-undefined.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Please read the [Rustonomicon] before writing unsafe code.
types are passed in a (nested) field of a compound type, but not behind
pointer indirections.
* Mutating immutable bytes. All bytes inside a [`const`] item are immutable.
The bytes owned by an immutable binding are immutable, unless those bytes are part of an [`UnsafeCell<U>`].
The bytes owned by an immutable binding or immutable `static` are immutable, unless those bytes are part of an [`UnsafeCell<U>`].

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.

Expand Down
2 changes: 2 additions & 0 deletions src/items/external-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ of initializing the static.
Extern statics can be either immutable or mutable just like [statics] outside of external blocks.
An immutable static *must* be initialized before any Rust code is executed. It is not enough for
the static to be initialized before Rust code reads from it.
Once Rust code runs, mutating an immutable static (from inside or outside Rust) is UB,
except if the mutation happens to bytes inside of an `UnsafeCell`.

## ABI

Expand Down

0 comments on commit 15e0f7d

Please sign in to comment.