You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){letmut a = vec![1,2,3];let b = &mut a;// &mut borrow of `a` starts here// some code
b[1] = 123;println!("{:?}", a);// trying to access `a` as a shared borrow, so giving an error}// &mut borrow of `a` ends here
It seems to compile and run fine without any error on my machine
i'm new in rust too, i compiled this code and received the same result that u. I know that the language is retro-compatibility. In my mind that is just a mistake in documentation. I think that the correct code to get an error is
fnmain(){letmut a = vec![1,2,3];let b = a;// &mut borrow of `a` starts here// some code
b[1] = 123;println!("{:?}", a);// trying to access `a` as a shared borrow, so giving an error}
In this case the ownership of a is moved to b, and you can't access a in the print line
@trichimtrich Thanks for highlighting this. In 2018-2022, Rust ecosystem added more improvements for lifetimes, especially to improve DX; https://users.rust-lang.org/t/multiple-mutable-references-in-scope/20936 but the given code block was written in 2017. I think I need to double check NLLs in the examples of those sections and update them.
Hi, I'm new to Rust and trying the sample in this doc
https://learning-rust.github.io/docs/borrowing/
The code
It seems to compile and run fine without any error on my machine
Is it intended, or something has changed from the language itself.
The text was updated successfully, but these errors were encountered: