> In general moves are tracked at a pretty narrow level of granularity.
That makes sense, and it would make closures a lot nicer (rather than individually borrowing members of a struct), but I notice it doesn’t seem to work that way right now:
#[deriving(Show)]
struct Bar;
struct Foo {
pub foo: Bar,
pub bar: Bar,
}
fn main() {
let mut x = Foo { foo: Bar, bar: Bar };
let c = || {
x.foo = Bar;
};
println!("{}", x.bar); // error: cannot borrow x.bar as immutable because x is also borrowed as mutable
}
> you could imagine rules that say “if you move f, you can never again touch any subfields of f w
ithout restoring f as a unit”.
I like this as a nice middle ground. Restoring the individual fields of f seems error prone and difficult to read - I’d be very inclined to have the definition of the struct open in another tab, just to make sure all the fields really are being restored. Restoring as a unit makes sure it all happens in one sane place, and helps assure the reader that all the fields really are restored at that point.