Skip to content

Commit c98c1b7

Browse files
committed
Rollup merge of #31984 - xaocon:master, r=steveklabnik
Had a discussion at https://www.reddit.com/r/rust/comments/488mjv/borrowing_or_returning_ownership/ about how an example could be worded more clearly and tried to take my recommendation and expand upon it with further information provided in the post.
2 parents 5b40e9b + ae9121b commit c98c1b7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ fn main() {
211211
```
212212

213213
In other words, the mutable borrow is held through the rest of our example. What
214-
we want is for the mutable borrow to end _before_ we try to call `println!` and
215-
make an immutable borrow. In Rust, borrowing is tied to the scope that the
216-
borrow is valid for. And our scopes look like this:
214+
we want is for the mutable borrow by `y` to end so that the resource can be
215+
returned to the owner, `x`. `x` can then provide a mutable borrow to `println!`.
216+
In Rust, borrowing is tied to the scope that the borrow is valid for. And our
217+
scopes look like this:
217218

218219
```rust,ignore
219220
let mut x = 5;
@@ -378,4 +379,3 @@ statement 1 at 3:14
378379

379380
In the above example, `y` is declared before `x`, meaning that `y` lives longer
380381
than `x`, which is not allowed.
381-

0 commit comments

Comments
 (0)