From c96c0a74cbed126cc288ce66a47b55dd565f457b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 20 Oct 2024 10:30:04 +0200 Subject: [PATCH 1/3] attempt to clarify 'static' unique address guarantees --- src/items/static-items.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/items/static-items.md b/src/items/static-items.md index f7e47736c..71457bfee 100644 --- a/src/items/static-items.md +++ b/src/items/static-items.md @@ -12,21 +12,26 @@ r[items.static.syntax] > allowed semantically within `extern` blocks. r[items.static.intro] -A *static item* is similar to a [constant], except that it represents a precise -memory location in the program. All references to the static refer to the same -memory location. +A *static item* is similar to a [constant], except that it represents an allocated object in the +program that is initialized with the initializer expression. All references and raw pointers to the +static refer to the same allocated object. r[items.static.lifetime] -Static items have the `static` lifetime, which outlives all -other lifetimes in a Rust program. Static items do not call [`drop`] at the -end of the program. +Static items have the `static` lifetime, which outlives all other lifetimes in a Rust program. +Static items do not call [`drop`] at the end of the program. + +r[items.static.storage-disjointness] +This allocated object is disjoint from all other `static` objects as well as heap-allocated and +stack-allocated variables. However, the storage of immutable `static` items can overlap with objects +that do not themselves have a unique address, such as [promoteds] and [`const` items][constant]. r[items.static.namespace] The static declaration defines a static value in the [value namespace] of the module or block where it is located. r[items.static.init] The static initializer is a [constant expression] evaluated at compile time. -Static initializers may refer to other statics. +Static initializers may refer to and read from other statics. +When reading from mutable statics, they read the initial value of that static. r[items.static.read-only] Non-`mut` static items that contain a type that is not [interior mutable] may @@ -173,3 +178,4 @@ following are true: [_Expression_]: ../expressions.md [value namespace]: ../names/namespaces.md [_ItemSafety_]: functions.md +[promoteds]: ../destructors.md#constant-promotion From 8dde3eba9aadaa2c0a054da731a91f2ef55c6a33 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 7 Nov 2024 22:25:35 +0100 Subject: [PATCH 2/3] add a ZST exception --- src/items/static-items.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/items/static-items.md b/src/items/static-items.md index 71457bfee..e09c53ead 100644 --- a/src/items/static-items.md +++ b/src/items/static-items.md @@ -21,9 +21,10 @@ Static items have the `static` lifetime, which outlives all other lifetimes in a Static items do not call [`drop`] at the end of the program. r[items.static.storage-disjointness] -This allocated object is disjoint from all other `static` objects as well as heap-allocated and -stack-allocated variables. However, the storage of immutable `static` items can overlap with objects -that do not themselves have a unique address, such as [promoteds] and [`const` items][constant]. +If the `static` has a size of at least 1 byte, this allocated object is disjoint from all other +`static` objects as well as heap-allocated and stack-allocated variables. However, the storage of +immutable `static` items can overlap with objects that do not themselves have a unique address, such +as [promoteds] and [`const` items][constant]. r[items.static.namespace] The static declaration defines a static value in the [value namespace] of the module or block where it is located. From 0b7d4f792ff2759839a5d333d7f69a0f091e71ea Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 20 Nov 2024 18:47:13 +0100 Subject: [PATCH 3/3] clarify wording Co-authored-by: Josh Triplett --- src/items/static-items.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/items/static-items.md b/src/items/static-items.md index e09c53ead..7fb8897b6 100644 --- a/src/items/static-items.md +++ b/src/items/static-items.md @@ -21,7 +21,7 @@ Static items have the `static` lifetime, which outlives all other lifetimes in a Static items do not call [`drop`] at the end of the program. r[items.static.storage-disjointness] -If the `static` has a size of at least 1 byte, this allocated object is disjoint from all other +If the `static` has a size of at least 1 byte, this allocated object is disjoint from all other such `static` objects as well as heap-allocated and stack-allocated variables. However, the storage of immutable `static` items can overlap with objects that do not themselves have a unique address, such as [promoteds] and [`const` items][constant].