Skip to content

Commit 93b921c

Browse files
authored
Merge pull request #1657 from RalfJung/static
distinct 'static' items never overlap
2 parents 913ad06 + 08688f1 commit 93b921c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/items/static-items.md

+14-7
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@ r[items.static.syntax]
1111
> allowed semantically within `extern` blocks.
1212
1313
r[items.static.intro]
14-
A *static item* is similar to a [constant], except that it represents a precise
15-
memory location in the program. All references to the static refer to the same
16-
memory location.
14+
A *static item* is similar to a [constant], except that it represents an allocated object in the
15+
program that is initialized with the initializer expression. All references and raw pointers to the
16+
static refer to the same allocated object.
1717

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

2328
r[items.static.namespace]
2429
The static declaration defines a static value in the [value namespace] of the module or block where it is located.
2530

2631
r[items.static.init]
2732
The static initializer is a [constant expression] evaluated at compile time.
28-
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.
2935

3036
r[items.static.read-only]
3137
Non-`mut` static items that contain a type that is not [interior mutable] may
@@ -166,3 +172,4 @@ following are true:
166172
[_Expression_]: ../expressions.md
167173
[value namespace]: ../names/namespaces.md
168174
[_ItemSafety_]: functions.md
175+
[promoteds]: ../destructors.md#constant-promotion

0 commit comments

Comments
 (0)