@@ -425,6 +425,7 @@ scope of the initializer expression is extended.
425
425
r[ destructors.scope.lifetime-extension.exprs]
426
426
#### Extending based on expressions
427
427
428
+ r[ destructors.scope.lifetime-extension.exprs.extending]
428
429
For a let statement with an initializer, an * extending expression* is an
429
430
expression which is one of the following:
430
431
@@ -434,19 +435,26 @@ expression which is one of the following:
434
435
expression] , [ braced struct] [ struct expression ] , or [ tuple] [ tuple expression ]
435
436
expression.
436
437
* The arguments to an extending [ tuple struct] or [ tuple variant] constructor expression.
438
+ * The argument(s) to an extending [ ` pin! ` ] or [ ` format_args! ` ] [ macro invocation] expression.
437
439
* The final expression of any extending [ block expression] .
438
440
439
441
So the borrow expressions in ` &mut 0 ` , ` (&1, &mut 2) ` , and ` Some(&mut 3) `
440
442
are all extending expressions. The borrows in ` &0 + &1 ` and ` f(&mut 0) ` are not.
441
443
444
+ r[ destructors.scope.lifetime-extension.exprs.borrow]
442
445
The operand of any extending borrow expression has its temporary scope
443
446
extended.
444
447
448
+ r[ destructors.scope.lifetime-extension.exprs.macros]
449
+ The built-in macros [ ` pin! ` ] and [ ` format_args! ` ] create temporaries.
450
+ Any extending [ ` pin! ` ] or [ ` format_args! ` ] [ macro invocation] expression has an extended temporary scope.
451
+
445
452
#### Examples
446
453
447
454
Here are some examples where expressions have extended temporary scopes:
448
455
449
456
``` rust
457
+ # use std :: pin :: pin;
450
458
# fn temp () {}
451
459
// The temporary that stores the result of `temp()` lives in the same scope
452
460
// as x in these cases.
@@ -456,6 +464,8 @@ let x = &temp() as &dyn Send;
456
464
# x ;
457
465
let x = (& * & temp (),);
458
466
# x ;
467
+ let x = pin! (temp ());
468
+ # x ;
459
469
let x = { [Some (& temp ()) ] };
460
470
# x ;
461
471
let ref x = temp ();
@@ -510,6 +520,7 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
510
520
[ initialized ] : glossary.md#initialized
511
521
[ interior mutability ] : interior-mutability.md
512
522
[ lazy boolean expression ] : expressions/operator-expr.md#lazy-boolean-operators
523
+ [ macro invocation ] : macros.md#macro-invocation
513
524
[ non-unwinding ABI boundary ] : items/functions.md#unwinding
514
525
[ panic ] : panic.md
515
526
[ place context ] : expressions.md#place-expressions-and-value-expressions
@@ -554,3 +565,6 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
554
565
[ `match` ] : expressions/match-expr.md
555
566
[ `while let` ] : expressions/loop-expr.md#while-let-patterns
556
567
[ `while` ] : expressions/loop-expr.md#predicate-loops
568
+
569
+ [ `pin!` ] : std::pin::pin
570
+ [ `format_args!` ] : core::format_args
0 commit comments