diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 1d9e05f6774..19bebea7cb8 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -62,13 +62,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { Origin::Mir, ); - err.span_label( - span, - format!( - "value {} here after move", - desired_action.as_verb_in_past_tense() - ), - ); + let mut is_loop_move = false; for moi in mois { let move_msg = ""; //FIXME: add " (into closure)" let move_span = self.mir.source_info(self.move_data.moves[*moi].source).span; @@ -77,10 +71,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { span, format!("value moved{} here in previous iteration of loop", move_msg), ); + is_loop_move = true; } else { err.span_label(move_span, format!("value moved{} here", move_msg)); }; } + if !is_loop_move { + err.span_label( + span, + format!( + "value {} here after move", + desired_action.as_verb_in_past_tense() + ), + ); + } if let Some(ty) = self.retrieve_type_for_place(place) { let needs_note = match ty.sty { diff --git a/src/test/ui/borrowck/issue-41962.stderr b/src/test/ui/borrowck/issue-41962.stderr index 4522029593f..50d51c4d907 100644 --- a/src/test/ui/borrowck/issue-41962.stderr +++ b/src/test/ui/borrowck/issue-41962.stderr @@ -31,10 +31,7 @@ error[E0382]: use of moved value: `maybe.0` (Mir) --> $DIR/issue-41962.rs:17:21 | 17 | if let Some(thing) = maybe { - | ^^^^^ - | | - | value used here after move - | value moved here in previous iteration of loop + | ^^^^^ value moved here in previous iteration of loop | = note: move occurs because `maybe.0` has type `std::vec::Vec`, which does not implement the `Copy` trait