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
+12Lines changed: 12 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -442,11 +442,17 @@ 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!`] 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
+
445
450
#### Examples
446
451
447
452
Here are some examples where expressions have extended temporary scopes:
448
453
449
454
```rust
455
+
# usestd::pin::pin;
450
456
# fntemp() {}
451
457
// The temporary that stores the result of `temp()` lives in the same scope
452
458
// as x in these cases.
@@ -456,6 +462,8 @@ let x = &temp() as &dyn Send;
456
462
# x;
457
463
letx= (&*&temp(),);
458
464
# x;
465
+
letx=pin!(temp());
466
+
# x;
459
467
letx= { [Some(&temp()) ] };
460
468
# x;
461
469
letrefx=temp();
@@ -510,6 +518,7 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
0 commit comments