book
book copied to clipboard
Misinformation wrt the borrowing rules
Please stop spreading misinformation. This is perfectly good code using the latest version of Rust:
fn main() {
let mut x = 5;
let y = &mut x;
*y += 1;
println!("{}", x);
}
The compiler doesn't give the following error message you claim it does:
error: cannot borrow `x` as immutable because it is also borrowed as mutable
println!("{}", x);
^
Probably in a previous version of Rust this error was returned, but the version is not specified in the text, and if this part is outdated, probably there are many more irrelevant parts in the book.
Source: https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/first-edition/references-and-borrowing.html