Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ expression which is one of the following:
expression.
* The arguments to an extending [tuple struct] or [tuple variant] constructor expression.
* The final expression of any extending [block expression].
* The arm(s) of an extending [`match`] expression.
* The final expressions of an extending [`if`] expression's consequent, `else if`, and `else` blocks.

So the borrow expressions in `&mut 0`, `(&1, &mut 2)`, and `Some(&mut 3)`
are all extending expressions. The borrows in `&0 + &1` and `f(&mut 0)` are not.
Expand All @@ -448,15 +450,22 @@ Here are some examples where expressions have extended temporary scopes:

```rust
# fn temp() {}
# trait Use { fn use_temp(&self) -> &Self { self } }
# impl Use for () {}
// The temporary that stores the result of `temp()` lives in the same scope
// as x in these cases.
let x = &temp();
# x;
let x = &temp() as &dyn Send;
# x;
let x = (&*&temp(),);
# x;
let x = { [Some(&temp()) ] };
# x;
let x = match () { _ => &temp() };
# x;
let x = if true { &temp() } else { &temp() };
# x;
let ref x = temp();
# x;
let ref x = *&temp();
# x;
```
Expand All @@ -471,8 +480,11 @@ Here are some examples where expressions don't have extended temporary scopes:
// end of the let statement in these cases.

let x = std::convert::identity(&temp()); // ERROR
# x;
let x = (&temp()).use_temp(); // ERROR
# x;
let x = match &temp() { x => x }; // ERROR
# x;
```

r[destructors.forget]
Expand Down