File tree Expand file tree Collapse file tree 3 files changed +9
-7
lines changed Expand file tree Collapse file tree 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]
4242 Recursively defining constants is not allowed.
4343
4444r[ 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.
4649
4750r[ const-eval.const-expr.tuple]
4851* [ Tuple expressions] .
@@ -177,6 +180,7 @@ of whether you are building on a `64` bit or a `32` bit system.
177180[ enum discriminants ] : items/enumerations.md#discriminants
178181[ expression statements ] : statements.md#expression-statements
179182[ expressions ] : expressions.md
183+ [ `extern` statics ] : items/external-blocks.md#statics
180184[ field ] : expressions/field-expr.md
181185[ functions ] : items/functions.md
182186[ 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 {
3939};
4040```
4141
42+ The final value of a ` const ` item cannot contain references to anything mutable.
43+
4244The constant expression may only be omitted in a [ trait definition] .
4345
4446## Constants with Destructors
Original file line number Diff line number Diff line change @@ -22,11 +22,7 @@ Static initializers may refer to other statics.
2222Non-` mut ` static items that contain a type that is not [ interior mutable] may
2323be placed in read-only memory.
2424
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.
3026
3127The initializer expression must be omitted in an [ external block] , and must be
3228provided for free static items.
@@ -131,7 +127,7 @@ It can be confusing whether or not you should use a constant item or a static
131127item. Constants should, in general, be preferred over statics unless one of the
132128following are true:
133129
134- * Large amounts of data are being stored
130+ * Large amounts of data are being stored.
135131* The single-address property of statics is required.
136132* Interior mutability is required.
137133
You can’t perform that action at this time.
0 commit comments