Skip to content

Commit 35ae17a

Browse files
committed
attempt to clarify 'static' unique address guarantees
1 parent 46d65f8 commit 35ae17a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/items/static-items.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88
> [^extern-safety]: The `safe` and `unsafe` function qualifiers are only
99
> allowed semantically within `extern` blocks.
1010
11-
A *static item* is similar to a [constant], except that it represents a precise
12-
memory location in the program. All references to the static refer to the same
13-
memory location. Static items have the `static` lifetime, which outlives all
14-
other lifetimes in a Rust program. Static items do not call [`drop`] at the
15-
end of the program.
11+
A *static item* is similar to a [constant], except that it represents an allocated object in the
12+
program that is initialized with the initializer expression. All references and raw pointers to the
13+
static refer to the same allocated object. Static items have the `static` lifetime, which outlives
14+
all other lifetimes in a Rust program. Static items do not call [`drop`] at the end of the program.
15+
16+
This allocated object is disjoint from all other `static` objects as well as heap-allocated and
17+
stack-allocated variables. However, the storage of immutable `static` items can overlap with objects
18+
that do not themselves have a unique address, such as promoteds and `const` items.
1619

1720
The static declaration defines a static value in the [value namespace] of the module or block where it is located.
1821

1922
The static initializer is a [constant expression] evaluated at compile time.
20-
Static initializers may refer to other statics.
23+
Static initializers may refer to and even read from other statics.
24+
When reading from mutable statics, they read the initial value of that static.
2125

2226
Non-`mut` static items that contain a type that is not [interior mutable] may
2327
be placed in read-only memory.

0 commit comments

Comments
 (0)