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
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -434,19 +434,22 @@ expression which is one of the following:
434
434
expression], [braced struct][struct expression], or [tuple][tuple expression]
435
435
expression.
436
436
* 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.
437
438
* The final expression of any extending [block expression].
438
439
439
440
So the borrow expressions in `&mut 0`, `(&1, &mut 2)`, and `Some(&mut 3)`
440
441
are all extending expressions. The borrows in `&0 + &1` and `f(&mut 0)` are not.
441
442
442
443
The operand of any extending borrow expression has its temporary scope
443
444
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.
444
446
445
447
#### Examples
446
448
447
449
Here are some examples where expressions have extended temporary scopes:
448
450
449
451
```rust
452
+
# usestd::pin::pin;
450
453
# fntemp() {}
451
454
// The temporary that stores the result of `temp()` lives in the same scope
452
455
// as x in these cases.
@@ -456,6 +459,8 @@ let x = &temp() as &dyn Send;
456
459
# x;
457
460
letx= (&*&temp(),);
458
461
# x;
462
+
letx=pin!(temp());
463
+
# x;
459
464
letx= { [Some(&temp()) ] };
460
465
# x;
461
466
letrefx=temp();
@@ -510,6 +515,7 @@ There is one additional case to be aware of: when a panic reaches a [non-unwindi
0 commit comments