From 417784bd38d0971e6f0be3d18fe7ce9cc66cd71a Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Tue, 1 Jan 2019 14:06:01 -0500 Subject: [PATCH] Update and extract an error message --- nostarch/chapter-08-error-message-updates.md | 15 +++++++++++++++ src/ch08-01-vectors.md | 20 ++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 nostarch/chapter-08-error-message-updates.md diff --git a/nostarch/chapter-08-error-message-updates.md b/nostarch/chapter-08-error-message-updates.md new file mode 100644 index 000000000..8a7e3b994 --- /dev/null +++ b/nostarch/chapter-08-error-message-updates.md @@ -0,0 +1,15 @@ +Please replace the error message on page 133 with this one: + +``` +error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable + --> src/main.rs:6:5 + | +4 | let first = &v[0]; + | - immutable borrow occurs here +5 | +6 | v.push(6); + | ^^^^^^^^^ mutable borrow occurs here +7 | +8 | println!("The first element is: {}", first); + | ----- immutable borrow later used here +``` diff --git a/src/ch08-01-vectors.md b/src/ch08-01-vectors.md index c80c718b0..ba091fe34 100644 --- a/src/ch08-01-vectors.md +++ b/src/ch08-01-vectors.md @@ -176,16 +176,16 @@ Compiling this code will result in this error: ```text error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable - --> src/main.rs:10:5 - | -8 | let first = &v[0]; - | - immutable borrow occurs here -9 | -10 | v.push(6); - | ^^^^^^^^^ mutable borrow occurs here -11 | -12 | println!("The first element is: {}", first); - | ----- borrow later used here + --> src/main.rs:6:5 + | +4 | let first = &v[0]; + | - immutable borrow occurs here +5 | +6 | v.push(6); + | ^^^^^^^^^ mutable borrow occurs here +7 | +8 | println!("The first element is: {}", first); + | ----- immutable borrow later used here ``` The code in Listing 8-7 might look like it should work: why should a reference