Skip to content

Commit 6c07751

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

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/destructors.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,18 @@ 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!`] expand to borrow their arguments.
447+
> They are subject to lifetime extension as follows:
448+
> * The argument to an extending [`pin!`] macro invocation expression is extending and has an extended temporary scope.
449+
> * Apart from the format string, the arguments to an extending [`format_args!`] macro invocation expression are extending and have extended temporary scopes.
450+
445451
#### Examples
446452

447453
Here are some examples where expressions have extended temporary scopes:
448454

449455
```rust
456+
# use std::pin::pin;
450457
# fn temp() {}
451458
// The temporary that stores the result of `temp()` lives in the same scope
452459
// as x in these cases.
@@ -456,6 +463,8 @@ let x = &temp() as &dyn Send;
456463
# x;
457464
let x = (&*&temp(),);
458465
# x;
466+
let x = pin!(temp());
467+
# x;
459468
let x = { [Some(&temp()) ] };
460469
# x;
461470
let ref x = temp();
@@ -510,6 +519,7 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
510519
[initialized]: glossary.md#initialized
511520
[interior mutability]: interior-mutability.md
512521
[lazy boolean expression]: expressions/operator-expr.md#lazy-boolean-operators
522+
[macro invocation]: macros.md#macro-invocation
513523
[non-unwinding ABI boundary]: items/functions.md#unwinding
514524
[panic]: panic.md
515525
[place context]: expressions.md#place-expressions-and-value-expressions
@@ -554,3 +564,6 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
554564
[`match`]: expressions/match-expr.md
555565
[`while let`]: expressions/loop-expr.md#while-let-patterns
556566
[`while`]: expressions/loop-expr.md#predicate-loops
567+
568+
[`pin!`]: std::pin::pin
569+
[`format_args!`]: core::format_args

0 commit comments

Comments
 (0)