book icon indicating copy to clipboard operation
book copied to clipboard

Ch. 4.2 — No mention of variables not being mutable while borrowed

Open LuuBluum opened this issue 3 years ago • 0 comments

  • [X] I have checked the latest main branch to see if this has already been fixed
  • [X] I have searched existing issues and pull requests for duplicates

URL to the section(s) of the book with this problem:

https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html

Description of the problem:

Nowhere in the chapter on references and borrowing does it mention that a variable, while borrowed, cannot be mutated until all references are dead. It specifically remarks that "users of an immutable reference don't expect the value to suddenly change out from under them!", but conceptually this is not true if you do not know that a mutable variable cannot be changed while the reference is live.

I mention this as someone using this book to learn Rust, having this exact question when reaching the point in the book.

Suggested fix:

Address, with an example, a mutable variable being changed after a reference is created against that variable resulting in a compilation error.

LuuBluum avatar May 04 '22 15:05 LuuBluum