Hi all,
This code fails as expected at let c = a;
with compile error "use of moved value: a
":
fn main() {
let a: &mut i32 = &mut 0;
let b = a;
let c = a;
}
a is moved into b and is no longer available for an assignment to c. So far, so good.
However, if I just annotate b
's type and leave everything else alone:
fn main() {
let a: &mut i32 = &mut 0;
let b: &mut i32 = a;
let c = a;
}
the code fails again at let c = a;
But this time with a very different error message: "cannot move out of a
because it is borrowed … borrow of *a
occurs here: let b: &mut i32 = a;
"
So, if I just annotate b
's type: no move of a
into b
, but instead a “re”-borrow of *a
?
What am I missing?
Cheers.
(cross-posted to http://stackoverflow.com/q/30535529/4951150)