Skip to content

Commit

Permalink
Adding consider changing to & suggestion for let bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurikholkar committed May 2, 2017
1 parent 50517d5 commit 478b7d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,19 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &Vec<Move
let mut err = report_cannot_move_out_of(bccx, error.move_from.clone());
let mut is_first_note = true;
match error.move_to_places.get(0) {
Some(&MovePlace { pat_source: PatternSource::LetDecl(_), .. }) => {
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) {
if snippet.len() > 10 {
err.help(&format!("consider borrowing this with `&`"));
} else {
err.help(&format!("consider changing to `&{}`", snippet));
}
}

}
_ => {
for move_to in &error.move_to_places {
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0507]: cannot move out of indexed content
|
19 | let e = f.v[0];
| ^^^^^^ cannot move out of indexed content
|
= help: consider changing to `&f.v[0]`

error: aborting due to previous error

0 comments on commit 478b7d9

Please sign in to comment.