Closed
Description
When moving out of a value into a new let binding, AST borrowck suggests using a reference, but MIR borrowck does not.
e.g. for E0508:
struct NonCopy;
fn main() {
let array = [NonCopy; 1];
let _value = array[0]; //[ast]~ ERROR [E0508]
//[mir]~^ ERROR [E0508]
}
We have the following error message
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Ast)
--> /home/ariel/Rust/rust-master/src/test/compile-fail/E0508.rs:18:18
|
18 | let _value = array[0]; //[ast]~ ERROR [E0508]
| ^^^^^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&array[0]`
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Mir)
--> /home/ariel/Rust/rust-master/src/test/compile-fail/E0508.rs:18:18
|
18 | let _value = array[0]; //[ast]~ ERROR [E0508]
| ^^^^^^^^ cannot move out of here
error: aborting due to 2 previous errors
See that the help is only in the AST. We should port that help message to MIR borrowck.
The help message is generated in this place in AST borrowck:
rust/src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Lines 77 to 87 in 02b4d3d