Skip to content

Consider changing to & for let bindings #40402 #41640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 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,16 @@ 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) {
err.span_suggestion(initializer.span,
"consider using a reference instead",
format!("&{}", snippet));
}
}
_ => {
for move_to in &error.move_to_places {
Expand Down
5 changes: 4 additions & 1 deletion src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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 using a reference instead `&f.v[0]`
| cannot move out of indexed content

error: aborting due to previous error