In Rust 1.0, does the compiler consider the evaluation order when analyzing ownership in an expression? For instance:
struct Foo { val:usize }
fn main() {
let mut v:Vec<Foo> = Vec::with_capacity(1);
v.push(Foo{val:0});
let f = Foo{val:0};
v[f.val] = f;
}
It could not be compiled because the index is in the array f.val, but fmoves to the array. I do not understand why using f.valas an index on LHS may contradict the transfer of ownership of f to RHS.
source
share