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
Copy file name to clipboardExpand all lines: src/destructors.md
+13Lines changed: 13 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -442,11 +442,18 @@ are all extending expressions. The borrows in `&0 + &1` and `f(&mut 0)` are not.
442
442
The operand of any extending borrow expression has its temporary scope
443
443
extended.
444
444
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
+
445
451
#### Examples
446
452
447
453
Here are some examples where expressions have extended temporary scopes:
448
454
449
455
```rust
456
+
# usestd::pin::pin;
450
457
# fntemp() {}
451
458
// The temporary that stores the result of `temp()` lives in the same scope
452
459
// as x in these cases.
@@ -456,6 +463,8 @@ let x = &temp() as &dyn Send;
456
463
# x;
457
464
letx= (&*&temp(),);
458
465
# x;
466
+
letx=pin!(temp());
467
+
# x;
459
468
letx= { [Some(&temp()) ] };
460
469
# x;
461
470
letrefx=temp();
@@ -510,6 +519,7 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
0 commit comments