Skip to content

Commit 64644b2

Browse files
committed
specify lifetime extension of pin! and format_args! arguments
1 parent 0a25dea commit 64644b2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/destructors.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,19 +434,22 @@ expression which is one of the following:
434434
expression], [braced struct][struct expression], or [tuple][tuple expression]
435435
expression.
436436
* The arguments to an extending [tuple struct] or [tuple variant] constructor expression.
437+
* The argument to an extending [`pin!`] or the value arguments to an extending [`format_args!`] [macro invocation] expression.
437438
* The final expression of any extending [block expression].
438439

439440
So the borrow expressions in `&mut 0`, `(&1, &mut 2)`, and `Some(&mut 3)`
440441
are all extending expressions. The borrows in `&0 + &1` and `f(&mut 0)` are not.
441442

442443
The operand of any extending borrow expression has its temporary scope
443444
extended.
445+
Likewise, the argument to any extending [`pin!`] macro invocation expression and the value arguments to any extending [`format_args!`] macro invocation expression have their temporary scopes extended.
444446

445447
#### Examples
446448

447449
Here are some examples where expressions have extended temporary scopes:
448450

449451
```rust
452+
# use std::pin::pin;
450453
# fn temp() {}
451454
// The temporary that stores the result of `temp()` lives in the same scope
452455
// as x in these cases.
@@ -456,6 +459,8 @@ let x = &temp() as &dyn Send;
456459
# x;
457460
let x = (&*&temp(),);
458461
# x;
462+
let x = pin!(temp());
463+
# x;
459464
let x = { [Some(&temp()) ] };
460465
# x;
461466
let ref x = temp();
@@ -510,6 +515,7 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
510515
[initialized]: glossary.md#initialized
511516
[interior mutability]: interior-mutability.md
512517
[lazy boolean expression]: expressions/operator-expr.md#lazy-boolean-operators
518+
[macro invocation]: macros.md#macro-invocation
513519
[non-unwinding ABI boundary]: items/functions.md#unwinding
514520
[panic]: panic.md
515521
[place context]: expressions.md#place-expressions-and-value-expressions
@@ -554,3 +560,6 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
554560
[`match`]: expressions/match-expr.md
555561
[`while let`]: expressions/loop-expr.md#while-let-patterns
556562
[`while`]: expressions/loop-expr.md#predicate-loops
563+
564+
[`pin!`]: std::pin::pin
565+
[`format_args!`]: core::format_args

0 commit comments

Comments
 (0)