Skip to content

Commit c96c0a7

Browse files
committed
attempt to clarify 'static' unique address guarantees
1 parent e4b5b61 commit c96c0a7

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/items/static-items.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,26 @@ r[items.static.syntax]
1212
> allowed semantically within `extern` blocks.
1313
1414
r[items.static.intro]
15-
A *static item* is similar to a [constant], except that it represents a precise
16-
memory location in the program. All references to the static refer to the same
17-
memory location.
15+
A *static item* is similar to a [constant], except that it represents an allocated object in the
16+
program that is initialized with the initializer expression. All references and raw pointers to the
17+
static refer to the same allocated object.
1818

1919
r[items.static.lifetime]
20-
Static items have the `static` lifetime, which outlives all
21-
other lifetimes in a Rust program. Static items do not call [`drop`] at the
22-
end of the program.
20+
Static items have the `static` lifetime, which outlives all other lifetimes in a Rust program.
21+
Static items do not call [`drop`] at the end of the program.
22+
23+
r[items.static.storage-disjointness]
24+
This allocated object is disjoint from all other `static` objects as well as heap-allocated and
25+
stack-allocated variables. However, the storage of immutable `static` items can overlap with objects
26+
that do not themselves have a unique address, such as [promoteds] and [`const` items][constant].
2327

2428
r[items.static.namespace]
2529
The static declaration defines a static value in the [value namespace] of the module or block where it is located.
2630

2731
r[items.static.init]
2832
The static initializer is a [constant expression] evaluated at compile time.
29-
Static initializers may refer to other statics.
33+
Static initializers may refer to and read from other statics.
34+
When reading from mutable statics, they read the initial value of that static.
3035

3136
r[items.static.read-only]
3237
Non-`mut` static items that contain a type that is not [interior mutable] may
@@ -173,3 +178,4 @@ following are true:
173178
[_Expression_]: ../expressions.md
174179
[value namespace]: ../names/namespaces.md
175180
[_ItemSafety_]: functions.md
181+
[promoteds]: ../destructors.md#constant-promotion

0 commit comments

Comments
 (0)