You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a let statement with an initializer, an *extending expression* is an
478
-
expression which is one of the following:
477
+
An *extending expression* is an expression which is one of the following:
479
478
480
-
* The initializer expression.
481
-
* The operand of an extending[borrow] expression.
482
-
* The [super operands] of an extending[super macro call] expression.
483
-
* The operand(s) of an extending [array][array expression], [cast][cast
479
+
* The initializer expression of a `let` statement or the body expression of a [static][static item] or [constant item].
480
+
* The operand of a[borrow] expression.
481
+
* The [super operands] of a[super macro call] expression.
482
+
* The operand(s) of an [array][array expression], [cast][cast
484
483
expression], [braced struct][struct expression], or [tuple][tuple expression]
485
484
expression.
486
-
* The arguments to an extending[tuple struct] or [tuple enum variant] constructor expression.
487
-
* The final expression of an extending[block expression] except for an [async block expression].
488
-
* The final expression of an extending [`if`] expression's consequent, `else if`, or `else` block.
489
-
* An arm expression of an extending[`match`] expression.
485
+
* The arguments to a[tuple struct] or [tuple enum variant] constructor expression.
486
+
* The final expression of a[block expression] except for an [async block expression].
487
+
* The final expression of an [`if`] expression's consequent, `else if`, or `else` block.
488
+
* An arm expression of a[`match`] expression.
490
489
491
490
> [!NOTE]
492
491
> The desugaring of a [destructuring assignment] makes its assigned value operand (the RHS) an extending expression within a newly-introduced block. For details, see [expr.assign.destructure.tmp-ext].
493
492
494
-
So the borrow expressions in `&mut 0`, `(&1, &mut 2)`, and `Some(&mut 3)`
493
+
> [!NOTE]
494
+
> `rustc` does not treat [array repeat operands] of [array] expressions as extending expressions. Whether it should is an open question.
495
+
>
496
+
> For details, see [Rust issue #146092](https://github.com/rust-lang/rust/issues/146092).
497
+
498
+
So the borrow expressions in `{ &mut 0 }`, `(&1, &mut 2)`, and `Some(&mut 3)`
495
499
are all extending expressions. The borrows in `&0 + &1` and `f(&mut 0)` are not.
The [super temporaries] of an extending [super macro call] expression have their [scopes][temporary scopes][extended].
505
+
The [scopes][temporary scopes] of the [super temporaries] of an extending [super macro call] expression are *extended through* the scope of the super macro call expression.
502
506
503
-
> [!NOTE]
504
-
> `rustc` does not treat [array repeat operands] of extending [array] expressions as extending expressions. Whether it should is an open question.
505
-
>
506
-
> For details, see [Rust issue #146092](https://github.com/rust-lang/rust/issues/146092).
If a temporary scope is extended through the scope of an extending expression, it is extended through that scope's [parent][destructors.scope.nesting].
509
+
510
+
r[destructors.scope.lifetime-extension.exprs.let]
511
+
A temporary scope extended through a `let` statement scope is [extended] to the scope of the block containing the `let` statement ([destructors.scope.lifetime-extension.let]).
A temporary scope extended through a [static][static item] or [constant item] scope or a [const block][const block expression] scope is [extended] to the end of the program ([destructors.scope.lifetime-extension.static]).
0 commit comments