Skip to content

Commit

Permalink
Using a span_suggestion to display use & hint
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurikholkar committed May 2, 2017
1 parent 478b7d9 commit 1c57bb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/librustc_borrowck/borrowck/gather_loans/move_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &Vec<Move
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));
}
err.span_suggestion(initializer.span,
"consider using a reference instead",
format!("&{}", snippet));
}

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

error: aborting due to previous error

0 comments on commit 1c57bb4

Please sign in to comment.