File tree 1 file changed +12
-6
lines changed
1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -115,16 +115,22 @@ resources for little benefit.
115
115
116
116
### Access to a ` const ` or ` static `
117
117
118
- Accesses to ` const ` s are always promotable, regardless of the body of the
119
- ` const ` . For instance, while the previous example was not legal, the
120
- following would be:
118
+ When accessing a ` const ` in a promotable context, the restrictions on single
119
+ assignment and named locals do not apply to the body of the ` const ` . All other
120
+ restrictions, notably that the result of the ` const ` cannot be ` Drop ` or mutable
121
+ through a reference still apply. For instance, while the previous example was
122
+ not legal, the following would be:
121
123
122
124
``` rust
123
- const NOT_WINDOWS : i32 = if cfg! (windows ) { 0 } else { 1 };
124
- let x : & 'static i32 = & NOT_WINDOWS ;
125
+ const BOOL : i32 = {
126
+ let ret = if cfg! (windows ) { 0 } else { 1 };
127
+ ret
128
+ };
129
+
130
+ let x : & 'static i32 = & BOOL ;
125
131
```
126
132
127
- However, an access to a ` static ` is only promotable within the initializer of
133
+ An access to a ` static ` is only promotable within the initializer of
128
134
another ` static ` .
129
135
130
136
### Panics
You can’t perform that action at this time.
0 commit comments