Skip to content

Commit d6159b7

Browse files
committed
Clarifying deallocation order of resources within same scope
1 parent 04daae7 commit d6159b7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/doc/trpl/references-and-borrowing.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ In other words, `y` is only valid for the scope where `x` exists. As soon as
336336
the borrow ‘doesn’t live long enough’ because it’s not valid for the right
337337
amount of time.
338338

339-
The same problem occurs when the reference is declared _before_ the variable it refers to:
339+
The same problem occurs when the reference is declared _before_ the variable it
340+
refers to. This is because resources within the same scope are freed in the
341+
opposite order they were declared:
340342

341343
```rust,ignore
342344
let y: &i32;
@@ -369,3 +371,6 @@ statement 1 at 3:14
369371
println!("{}", y);
370372
}
371373
```
374+
375+
In the above example, `y` is declared before `x`, meaning that `y` lives longer
376+
than `x`, which is not allowed.

0 commit comments

Comments
 (0)