Description
The AST-borrowck is often able to distinguish a path that was never assigned into (i.e. "uninitialized") from a path that had previously held a value but that value was subsequently moved elsewhere (i.e. "moved out of").
The MIR-borrowck currently uniformly reports both cases as instances of "uninitialized" state.
As an example: for the test src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs
, we have these diagnostics emitted:
% ./build/x86_64-unknown-l\
inux-gnu/stage1/bin/rustc -Z borrowck-mir ../src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs
error[E0382]: use of moved value: `x` (Ast)
--> ../src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs:31:20
|
31 | let _y = {x} + x.clone(); // the `{x}` forces a move to occur
| - ^ value used here after move
| |
| value moved here
|
= note: move occurs because `x` has type `foo`, which does not implement the `Copy` trait
error[E0381]: borrow of possibly uninitialized variable: `x` (Mir)
--> ../src/test/compile-fail/borrowck/borrowck-loan-in-overloaded-op.rs:31:20
|
31 | let _y = {x} + x.clone(); // the `{x}` forces a move to occur
| ^ use of possibly uninitialized `x`
error: aborting due to 2 previous errors
The first one is AST-borrowck, the second one MIR-borrowck.
Note in particular that AST-borrowck not only uses more precise language, but more importantly, it reports the specific span where the preceding move out occurred. This is perhaps the most important aspect of the diagnostic (especially for new-comers to Rust and move-semantics).