Skip to content

Commit 28dfc8c

Browse files
authored
Merge pull request #323 from Havvy/fix-322
Statics may sometimes inline.
2 parents 7fe4252 + b066dfd commit 28dfc8c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/items/static-items.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@
66
> `=` [_Expression_] `;`
77
88
A *static item* is similar to a [constant], except that it represents a precise
9-
memory location in the program. A static is never "inlined" at the usage site,
10-
and all references to it refer to the same memory location. Static items have
11-
the `static` lifetime, which outlives all other lifetimes in a Rust program.
12-
Static items may be placed in read-only memory if the type is not [interior
13-
mutable]. Static items do not call `drop` at the end of the program.
9+
memory location in the program. All references to the static refer to the same
10+
memory location. Static items have the `static` lifetime, which outlives all
11+
other lifetimes in a Rust program. Non-`mut` static items that contain a type
12+
that is not [interior mutable] may be placed in read-only memory. Static items
13+
do not call [`drop`] at the end of the program.
1414

1515
All access to a static is safe, but there are a number of restrictions on
1616
statics:
1717

1818
* The type must have the `Sync` trait bound to allow thread-safe access.
19-
* Statics allow using paths to statics in the
20-
[constant-expression](expressions.html#constant-expressions) used to
19+
* Statics allow using paths to statics in the [constant-expression] used to
2120
initialize them, but statics may not refer to other statics by value, only
2221
through a reference.
2322
* Constants cannot refer to statics.
@@ -33,7 +32,7 @@ modifications to a mutable static are safe with respect to other threads
3332
running in the same process.
3433

3534
Mutable statics are still very useful, however. They can be used with C
36-
libraries and can also be bound from C libraries (in an `extern` block).
35+
libraries and can also be bound from C libraries in an `extern` block.
3736

3837
```rust
3938
# fn atomic_add(_: &mut u32, _: u32) -> u32 { 2 }
@@ -66,10 +65,12 @@ item. Constants should, in general, be preferred over statics unless one of the
6665
following are true:
6766

6867
* Large amounts of data are being stored
69-
* The single-address or non-inlining property of statics is required.
68+
* The single-address property of statics is required.
7069
* Interior mutability is required.
7170

7271
[constant]: items/constant-items.html
72+
[`drop`]: destructors.html
73+
[constant expression]: expressions.html#constant-expressions
7374
[interior mutable]: interior-mutability.html
7475
[IDENTIFIER]: identifiers.html
7576
[_Type_]: types.html

0 commit comments

Comments
 (0)