My code is:
fn main() {
let mut foo = 1024;
let bar = &mut foo;
let baz:&mut i32 = bar;
let qux = bar;
assert_eq!(baz,qux);
}
Of course, this code has errors. However, what puzzles me is the error message:
error[E0505]: cannot move out of `bar` because it is borrowed
--> main.rs:5:15
|
4 | let baz:&mut i32 = bar;
| --- borrow of `*bar` occurs here
5 | let qux = bar;
| ^^^ move out of `bar` occurs here
6 | assert_eq!(baz,qux);
| -------------------- borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0505`.
The fourth line print borrow of '*bar', while the fifth line print move out of 'bar'. Why is that?(My rustc version is 1.55.0).