File tree 3 files changed +9
-7
lines changed
3 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,10 @@ r[const-eval.const-expr.path-item]
42
42
Recursively defining constants is not allowed.
43
43
44
44
r[ const-eval.const-expr.path-static]
45
- * Paths to [ statics] . These are only allowed within the initializer of a static.
45
+ * Paths to [ statics] with these restrictions and observations.
46
+ * In particular, reads and writes to any ` static ` , ` static mut ` or [ ` extern ` statics] is not allowed.
47
+ * Immutable borrows and pointers into immutable part of a ` static ` are allowed and observes the same restriction
48
+ on all other forms of [ borrow] s as mentioned below.
46
49
47
50
r[ const-eval.const-expr.tuple]
48
51
* [ Tuple expressions] .
@@ -177,6 +180,7 @@ of whether you are building on a `64` bit or a `32` bit system.
177
180
[ enum discriminants ] : items/enumerations.md#discriminants
178
181
[ expression statements ] : statements.md#expression-statements
179
182
[ expressions ] : expressions.md
183
+ [ `extern` statics ] : items/external-blocks.md#statics
180
184
[ field ] : expressions/field-expr.md
181
185
[ functions ] : items/functions.md
182
186
[ grouped ] : expressions/grouped-expr.md
Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ const BITS_N_STRINGS: BitsNStrings<'static> = BitsNStrings {
39
39
};
40
40
```
41
41
42
+ The final value of a ` const ` item cannot contain references to anything mutable.
43
+
42
44
The constant expression may only be omitted in a [ trait definition] .
43
45
44
46
## Constants with Destructors
Original file line number Diff line number Diff line change @@ -22,11 +22,7 @@ Static initializers may refer to other statics.
22
22
Non-` mut ` static items that contain a type that is not [ interior mutable] may
23
23
be placed in read-only memory.
24
24
25
- All access to a static is safe, but there are a number of restrictions on
26
- statics:
27
-
28
- * The type must have the ` Sync ` trait bound to allow thread-safe access.
29
- * Constants cannot refer to statics.
25
+ The type of an immutable static must implement the [ ` Sync ` ] ( std::marker::Sync ) trait.
30
26
31
27
The initializer expression must be omitted in an [ external block] , and must be
32
28
provided for free static items.
@@ -131,7 +127,7 @@ It can be confusing whether or not you should use a constant item or a static
131
127
item. Constants should, in general, be preferred over statics unless one of the
132
128
following are true:
133
129
134
- * Large amounts of data are being stored
130
+ * Large amounts of data are being stored.
135
131
* The single-address property of statics is required.
136
132
* Interior mutability is required.
137
133
You can’t perform that action at this time.
0 commit comments