File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -247,6 +247,21 @@ An access to a `static` is only promotable within the initializer of another
247247` static ` . This is for the same reason that ` const ` initializers
248248[ cannot access statics] ( const.md#reading-statics ) .
249249
250+ Crucially, however, the following is * not* legal:
251+
252+ ``` rust
253+ const X : Cell <i32 > = Cell :: new (5 ); // ok
254+ const XREF : & Cell <i32 > = & X ; // not ok
255+ fn main () {
256+ let x : & 'static _ = & X ; // not ok
257+ }
258+ ```
259+
260+ Just like allowing ` XREF ` would be a problem because, by the inlining semantics,
261+ every user of ` XREF ` should get their own ` Cell ` ; it would also be a problem to
262+ promote here because if that code getes executed multiple times (e.g. inside a
263+ loop), it should get a new ` Cell ` each time.
264+
250265### Named locals
251266
252267Promotable expressions cannot refer to named locals. This is not a technical
You can’t perform that action at this time.
0 commit comments