Further specify temporary scoping for statics and consts#2041
Further specify temporary scoping for statics and consts#2041dianne wants to merge 1 commit intorust-lang:masterfrom
statics and consts#2041Conversation
| For a let statement with an initializer, an *extending expression* is an | ||
| For a let statement with an initializer, a [static item], a [constant item], or a [const block][const block expression], an *extending expression* is an | ||
| expression which is one of the following: | ||
|
|
||
| * The initializer expression. | ||
| * The initializer expression of a let statement, the body of a static or constant item, or the final expression of a const block. | ||
| * The operand of an extending [borrow] expression. | ||
| * The [super operands] of an extending [super macro call] expression. | ||
| * The operand(s) of an extending [array][array expression], [cast][cast | ||
| expression], [braced struct][struct expression], or [tuple][tuple expression] | ||
| expression. | ||
| * The arguments to an extending [tuple struct] or [tuple enum variant] constructor expression. | ||
| * The final expression of an extending [block expression] except for an [async block expression]. | ||
| * The final expression of an extending [block expression] except for an [async block expression] or const block expression. |
There was a problem hiding this comment.
This in particular feels awkward to me, but I'm not sure how to make it read better without entirely reworking the format of the list and/or making "extending" a binary relation (mapping expressions to extended scopes). The first bullet point is a base case, which effectively duplicates destructors.scope.lifetime-extension.let (and now destructors.scope.lifetime-extension.static), except without specifying the scope of extended temporaries. This gets a bit messy for const blocks in particular: const blocks are one of the base cases (they extend temporaries to statics) but they also have to be an exception to the grammar for extending expressions (so that we're not also specifying that they extend temporaries to the end of a block when they appear in a let initializer).
|
Closing since most of this has been subsumed by #2051. Once rust-lang/rust#146098 goes through (or doesn't go through) I'll see if there's anything left that needs doing here and reopen/rework this if so. |
This PR applies various tweaks relating to how the destructors chapter handles
staticitems,constitems, andconstblocks. In particular:fnitems and closures so that they can work forstatics andconsts as well. In some cases, this was a bit awkward, so further reworks may be necessary. Most importantly, this specifies thatstaticandconstbodies are temporary scopes; this was a point of confusion in compiler comments, so I feel it should be documented here. See also Assert that non-extended temporaries andsuper letbindings have scopes rust#147471constblock lifetime extension to demonstrate that it extends borrowed temporaries to statics, preventing them from being dropped.