-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goal
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
Some(&MovePlace { pat_source: PatternSource::LetDecl(ref e), .. }) => { | |
// ignore patterns that are found at the top-level of a `let`; | |
// see `get_pattern_source()` for details | |
let initializer = | |
e.init.as_ref().expect("should have an initializer to get an error"); | |
if let Ok(snippet) = bccx.tcx.sess.codemap().span_to_snippet(initializer.span) { | |
err.span_suggestion(initializer.span, | |
"consider using a reference instead", | |
format!("&{}", snippet)); | |
} | |
} |
Metadata
Metadata
Assignees
Labels
A-NLLArea: Non-lexical lifetimes (NLL)Area: Non-lexical lifetimes (NLL)A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.NLL-diagnosticsWorking towards the "diagnostic parity" goalWorking towards the "diagnostic parity" goal