Skip to content

Commit 1c9c73c

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

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/destructors.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,17 @@ are all extending expressions. The borrows in `&0 + &1` and `f(&mut 0)` are not.
442442
The operand of any extending borrow expression has its temporary scope
443443
extended.
444444

445+
> [!NOTE]
446+
> [Invocations][macro invocation] of the built-in macros [`pin!`] and [`format_args!`] create temporaries.
447+
> Any extending [`pin!`] or [`format_args!`] macro invocation expression has an extended temporary scope.
448+
> Additionally, the argument to an extending [`pin!`] macro invocation expression is extending, and apart from the format string, the arguments to an extending [`format_args!`] macro invocation expression are extending.
449+
445450
#### Examples
446451

447452
Here are some examples where expressions have extended temporary scopes:
448453

449454
```rust
455+
# use std::pin::pin;
450456
# fn temp() {}
451457
// The temporary that stores the result of `temp()` lives in the same scope
452458
// as x in these cases.
@@ -456,6 +462,8 @@ let x = &temp() as &dyn Send;
456462
# x;
457463
let x = (&*&temp(),);
458464
# x;
465+
let x = pin!(temp());
466+
# x;
459467
let x = { [Some(&temp()) ] };
460468
# x;
461469
let ref x = temp();
@@ -510,6 +518,7 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
510518
[initialized]: glossary.md#initialized
511519
[interior mutability]: interior-mutability.md
512520
[lazy boolean expression]: expressions/operator-expr.md#lazy-boolean-operators
521+
[macro invocation]: macros.md#macro-invocation
513522
[non-unwinding ABI boundary]: items/functions.md#unwinding
514523
[panic]: panic.md
515524
[place context]: expressions.md#place-expressions-and-value-expressions
@@ -554,3 +563,6 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
554563
[`match`]: expressions/match-expr.md
555564
[`while let`]: expressions/loop-expr.md#while-let-patterns
556565
[`while`]: expressions/loop-expr.md#predicate-loops
566+
567+
[`pin!`]: std::pin::pin
568+
[`format_args!`]: core::format_args

0 commit comments

Comments
 (0)