Skip to content

Commit 1c57bb4

Browse files
committed
Using a span_suggestion to display use & hint
1 parent 478b7d9 commit 1c57bb4

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,10 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &Vec<Move
7979
let initializer =
8080
e.init.as_ref().expect("should have an initializer to get an error");
8181
if let Ok(snippet) = bccx.tcx.sess.codemap().span_to_snippet(initializer.span) {
82-
if snippet.len() > 10 {
83-
err.help(&format!("consider borrowing this with `&`"));
84-
} else {
85-
err.help(&format!("consider changing to `&{}`", snippet));
86-
}
82+
err.span_suggestion(initializer.span,
83+
"consider using a reference instead",
84+
format!("&{}", snippet));
8785
}
88-
8986
}
9087
_ => {
9188
for move_to in &error.move_to_places {

src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ error[E0507]: cannot move out of indexed content
22
--> $DIR/issue-40402-1.rs:19:13
33
|
44
19 | let e = f.v[0];
5-
| ^^^^^^ cannot move out of indexed content
6-
|
7-
= help: consider changing to `&f.v[0]`
5+
| ^^^^^^
6+
| |
7+
| help: consider using a reference instead `&f.v[0]`
8+
| cannot move out of indexed content
89

910
error: aborting due to previous error
1011

0 commit comments

Comments
 (0)