Skip to content

Commit 5d3db6d

Browse files
authored
Merge pull request #63 from RalfJung/projections
lifetime extension: mention how projections are handled
2 parents cc2711c + 48365e3 commit 5d3db6d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

promotion.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ There are a few different contexts where promotion is beneficial.
1313
"Lifetime extension" is a mechanism that affects code like `&3`:
1414
Instead of putting it on the stack, the `3` is allocated in global static memory
1515
and a reference with lifetime `'static` is provided. This is essentially an
16-
automatic transformation turning `&EXPR` into
17-
`{ const _PROMOTED = &EXPR; _PROMOTED }`, but only if `EXPR` qualifies.
16+
automatic transformation turning `&EXPR` into `{ const _PROMOTED = &EXPR;
17+
_PROMOTED }`, but only if `EXPR` qualifies. Topmost projections are not
18+
promoted, so `&EXPR.proj1.proj2` turns into `{ const _PROMOTED = &EXPR;
19+
&(*_PROMOTED).proj1.proj2 }`.
1820

1921
Note that promotion happens on the MIR, not on surface-level syntax. This is
2022
relevant when discussing e.g. handling of panics caused by overflowing

0 commit comments

Comments
 (0)