Skip to content

Commit a4d46b3

Browse files
committed
Tweak to mir borrow in a loop diagnostic
1 parent e027f5a commit a4d46b3

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Diff for: src/librustc_mir/borrow_check/error_reporting.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
6262
Origin::Mir,
6363
);
6464

65-
err.span_label(
66-
span,
67-
format!(
68-
"value {} here after move",
69-
desired_action.as_verb_in_past_tense()
70-
),
71-
);
65+
let mut is_loop_move = false;
7266
for moi in mois {
7367
let move_msg = ""; //FIXME: add " (into closure)"
7468
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> {
7771
span,
7872
format!("value moved{} here in previous iteration of loop", move_msg),
7973
);
74+
is_loop_move = true;
8075
} else {
8176
err.span_label(move_span, format!("value moved{} here", move_msg));
8277
};
8378
}
79+
if !is_loop_move {
80+
err.span_label(
81+
span,
82+
format!(
83+
"value {} here after move",
84+
desired_action.as_verb_in_past_tense()
85+
),
86+
);
87+
}
8488

8589
if let Some(ty) = self.retrieve_type_for_place(place) {
8690
let needs_note = match ty.sty {

Diff for: src/test/ui/borrowck/issue-41962.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ error[E0382]: use of moved value: `maybe.0` (Mir)
3131
--> $DIR/issue-41962.rs:17:21
3232
|
3333
17 | if let Some(thing) = maybe {
34-
| ^^^^^
35-
| |
36-
| value used here after move
37-
| value moved here in previous iteration of loop
34+
| ^^^^^ value moved here in previous iteration of loop
3835
|
3936
= note: move occurs because `maybe.0` has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
4037

0 commit comments

Comments
 (0)