book icon indicating copy to clipboard operation
book copied to clipboard

Misinformation wrt the borrowing rules

Open gyorgybalazsi opened this issue 1 year ago • 0 comments

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

gyorgybalazsi avatar Aug 20 '24 18:08 gyorgybalazsi