diff --git a/src/behavior-considered-undefined.md b/src/behavior-considered-undefined.md index 756b86db0..3e4c8a04d 100644 --- a/src/behavior-considered-undefined.md +++ b/src/behavior-considered-undefined.md @@ -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`]. + The bytes owned by an immutable binding or immutable `static` are immutable, unless those bytes are part of an [`UnsafeCell`]. 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. diff --git a/src/items/external-blocks.md b/src/items/external-blocks.md index ca42889b4..efbd08256 100644 --- a/src/items/external-blocks.md +++ b/src/items/external-blocks.md @@ -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