Skip to content

Commit bf43421

Browse files
committed
Auto merge of rust-lang#75302 - Aaron1011:feature/partial-move-diag, r=estebank
Be consistent when describing a move as a 'partial' in diagnostics When an error occurs due to a partial move, we would use the world "partial" in some parts of the error message, but not in others. This commit ensures that we use the word 'partial' in either all or none of the diagnostic messages. Additionally, we no longer describe a move out of a `Box` via `*` as a 'partial move'. This was a pre-existing issue, but became more noticable when the word 'partial' is used in more places.
2 parents 8ba2250 + 5f7436b commit bf43421

31 files changed

+300
-257
lines changed

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+56-21
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
113113
}
114114
}
115115

116-
let msg = ""; //FIXME: add "partially " or "collaterally "
116+
let is_partial_move = move_site_vec.iter().any(|move_site| {
117+
let move_out = self.move_data.moves[(*move_site).moi];
118+
let moved_place = &self.move_data.move_paths[move_out.path].place;
119+
// `*(_1)` where `_1` is a `Box` is actually a move out.
120+
let is_box_move = moved_place.as_ref().projection == &[ProjectionElem::Deref]
121+
&& self.body.local_decls[moved_place.local].ty.is_box();
122+
123+
!is_box_move
124+
&& used_place != moved_place.as_ref()
125+
&& used_place.is_prefix_of(moved_place.as_ref())
126+
});
127+
128+
let partial_str = if is_partial_move { "partial " } else { "" };
129+
let partially_str = if is_partial_move { "partially " } else { "" };
117130

118131
let mut err = self.cannot_act_on_moved_value(
119132
span,
120133
desired_action.as_noun(),
121-
msg,
134+
partially_str,
122135
self.describe_place_with_options(moved_place, IncludingDowncast(true)),
123136
);
124137

125138
self.add_moved_or_invoked_closure_note(location, used_place, &mut err);
126139

127140
let mut is_loop_move = false;
128-
let is_partial_move = move_site_vec.iter().any(|move_site| {
129-
let move_out = self.move_data.moves[(*move_site).moi];
130-
let moved_place = &self.move_data.move_paths[move_out.path].place;
131-
used_place != moved_place.as_ref() && used_place.is_prefix_of(moved_place.as_ref())
132-
});
141+
133142
for move_site in &move_site_vec {
134143
let move_out = self.move_data.moves[(*move_site).moi];
135144
let moved_place = &self.move_data.move_paths[move_out.path].place;
@@ -142,13 +151,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
142151
if location == move_out.source {
143152
err.span_label(
144153
span,
145-
format!("value moved{} here, in previous iteration of loop", move_msg),
154+
format!(
155+
"value {}moved{} here, in previous iteration of loop",
156+
partially_str, move_msg
157+
),
146158
);
147159
is_loop_move = true;
148160
} else if move_site.traversed_back_edge {
149161
err.span_label(
150162
move_span,
151-
format!("value moved{} here, in previous iteration of loop", move_msg),
163+
format!(
164+
"value {}moved{} here, in previous iteration of loop",
165+
partially_str, move_msg
166+
),
152167
);
153168
} else {
154169
if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } =
@@ -162,7 +177,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
162177
FnSelfUseKind::FnOnceCall => {
163178
err.span_label(
164179
fn_call_span,
165-
&format!("{} moved due to this call", place_name),
180+
&format!(
181+
"{} {}moved due to this call",
182+
place_name, partially_str
183+
),
166184
);
167185
err.span_note(
168186
var_span,
@@ -172,7 +190,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
172190
FnSelfUseKind::Operator { self_arg } => {
173191
err.span_label(
174192
fn_call_span,
175-
&format!("{} moved due to usage in operator", place_name),
193+
&format!(
194+
"{} {}moved due to usage in operator",
195+
place_name, partially_str
196+
),
176197
);
177198
if self.fn_self_span_reported.insert(fn_span) {
178199
err.span_note(
@@ -186,14 +207,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
186207
err.span_label(
187208
fn_call_span,
188209
&format!(
189-
"{} moved due to this implicit call to `.into_iter()`",
190-
place_name
210+
"{} {}moved due to this implicit call to `.into_iter()`",
211+
place_name, partially_str
191212
),
192213
);
193214
} else {
194215
err.span_label(
195216
fn_call_span,
196-
&format!("{} moved due to this method call", place_name),
217+
&format!(
218+
"{} {}moved due to this method call",
219+
place_name, partially_str
220+
),
197221
);
198222
}
199223
// Avoid pointing to the same function in multiple different
@@ -207,10 +231,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
207231
}
208232
}
209233
} else {
210-
err.span_label(move_span, format!("value moved{} here", move_msg));
234+
err.span_label(
235+
move_span,
236+
format!("value {}moved{} here", partially_str, move_msg),
237+
);
211238
move_spans.var_span_label(
212239
&mut err,
213-
format!("variable moved due to use{}", move_spans.describe()),
240+
format!(
241+
"variable {}moved due to use{}",
242+
partially_str,
243+
move_spans.describe()
244+
),
214245
);
215246
}
216247
}
@@ -250,9 +281,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
250281
err.span_label(
251282
span,
252283
format!(
253-
"value {} here {}",
284+
"value {} here after {}move",
254285
desired_action.as_verb_in_past_tense(),
255-
if is_partial_move { "after partial move" } else { "after move" },
286+
partial_str
256287
),
257288
);
258289
}
@@ -321,7 +352,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
321352
} else {
322353
None
323354
};
324-
self.note_type_does_not_implement_copy(&mut err, &note_msg, ty, span);
355+
self.note_type_does_not_implement_copy(&mut err, &note_msg, ty, span, partial_str);
325356
}
326357

327358
if let Some((_, mut old_err)) =
@@ -1398,8 +1429,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13981429

13991430
for moi in &self.move_data.loc_map[location] {
14001431
debug!("report_use_of_moved_or_uninitialized: moi={:?}", moi);
1401-
if mpis.contains(&self.move_data.moves[*moi].path) {
1402-
debug!("report_use_of_moved_or_uninitialized: found");
1432+
let path = self.move_data.moves[*moi].path;
1433+
if mpis.contains(&path) {
1434+
debug!(
1435+
"report_use_of_moved_or_uninitialized: found {:?}",
1436+
move_paths[path].place
1437+
);
14031438
result.push(MoveSite { moi: *moi, traversed_back_edge: is_back_edge });
14041439

14051440
// Strictly speaking, we could continue our DFS here. There may be

src/librustc_mir/borrow_check/diagnostics/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
412412
place_desc: &str,
413413
ty: Ty<'tcx>,
414414
span: Option<Span>,
415+
move_prefix: &str,
415416
) {
416417
let message = format!(
417-
"move occurs because {} has type `{}`, which does not implement the `Copy` trait",
418-
place_desc, ty,
418+
"{}move occurs because {} has type `{}`, which does not implement the `Copy` trait",
419+
move_prefix, place_desc, ty,
419420
);
420421
if let Some(span) = span {
421422
err.span_label(span, message);

src/librustc_mir/borrow_check/diagnostics/move_errors.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
445445
None => "value".to_string(),
446446
};
447447

448-
self.note_type_does_not_implement_copy(err, &place_desc, place_ty, Some(span));
448+
self.note_type_does_not_implement_copy(
449+
err,
450+
&place_desc,
451+
place_ty,
452+
Some(span),
453+
"",
454+
);
449455
} else {
450456
binds_to.sort();
451457
binds_to.dedup();
@@ -467,7 +473,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
467473
Some(desc) => format!("`{}`", desc),
468474
None => "value".to_string(),
469475
};
470-
self.note_type_does_not_implement_copy(err, &place_desc, place_ty, Some(span));
476+
self.note_type_does_not_implement_copy(err, &place_desc, place_ty, Some(span), "");
471477

472478
use_spans.args_span_label(err, format!("move out of {} occurs here", place_desc));
473479
use_spans
@@ -529,6 +535,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
529535
&format!("`{}`", self.local_names[*local].unwrap()),
530536
bind_to.ty,
531537
Some(binding_span),
538+
"",
532539
);
533540
}
534541
}

src/test/ui/async-await/issues/issue-66958-non-copy-infered-type-arg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ impl<S> Ia<S> {
88

99
async fn crash(self) {
1010
Self::partial(self.0);
11-
Self::full(self); //~ ERROR use of moved value: `self`
11+
Self::full(self); //~ ERROR use of partially moved value: `self`
1212
}
1313
}
1414

src/test/ui/async-await/issues/issue-66958-non-copy-infered-type-arg.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0382]: use of moved value: `self`
1+
error[E0382]: use of partially moved value: `self`
22
--> $DIR/issue-66958-non-copy-infered-type-arg.rs:11:20
33
|
44
LL | Self::partial(self.0);
5-
| ------ value moved here
5+
| ------ value partially moved here
66
LL | Self::full(self);
77
| ^^^^ value used here after partial move
88
|
9-
= note: move occurs because `self.0` has type `S`, which does not implement the `Copy` trait
9+
= note: partial move occurs because `self.0` has type `S`, which does not implement the `Copy` trait
1010

1111
error: aborting due to previous error
1212

src/test/ui/binding/issue-53114-borrow-checks.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ LL | drop(m);
88
LL | match m { _ => { } } // #53114: should eventually be accepted too
99
| ^ value used here after move
1010

11-
error[E0382]: use of moved value: `mm`
11+
error[E0382]: use of partially moved value: `mm`
1212
--> $DIR/issue-53114-borrow-checks.rs:27:11
1313
|
1414
LL | match mm { (_x, _) => { } }
15-
| -- value moved here
15+
| -- value partially moved here
1616
LL | match mm { (_, _y) => { } }
1717
| ^^ value used here after partial move
1818
|
19-
= note: move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait
19+
= note: partial move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait
2020

21-
error[E0382]: use of moved value: `mm`
21+
error[E0382]: use of partially moved value: `mm`
2222
--> $DIR/issue-53114-borrow-checks.rs:29:11
2323
|
2424
LL | match mm { (_, _y) => { } }
25-
| -- value moved here
25+
| -- value partially moved here
2626
LL |
2727
LL | match mm { (_, _) => { } }
2828
| ^^ value used here after partial move
2929
|
30-
= note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait
30+
= note: partial move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait
3131

3232
error[E0382]: use of moved value: `m`
3333
--> $DIR/issue-53114-borrow-checks.rs:36:16
@@ -39,26 +39,26 @@ LL | drop(m);
3939
LL | if let _ = m { } // #53114: should eventually be accepted too
4040
| ^ value used here after move
4141

42-
error[E0382]: use of moved value: `mm`
42+
error[E0382]: use of partially moved value: `mm`
4343
--> $DIR/issue-53114-borrow-checks.rs:41:22
4444
|
4545
LL | if let (_x, _) = mm { }
46-
| -- value moved here
46+
| -- value partially moved here
4747
LL | if let (_, _y) = mm { }
4848
| ^^ value used here after partial move
4949
|
50-
= note: move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait
50+
= note: partial move occurs because `mm.0` has type `M`, which does not implement the `Copy` trait
5151

52-
error[E0382]: use of moved value: `mm`
52+
error[E0382]: use of partially moved value: `mm`
5353
--> $DIR/issue-53114-borrow-checks.rs:43:21
5454
|
5555
LL | if let (_, _y) = mm { }
56-
| -- value moved here
56+
| -- value partially moved here
5757
LL |
5858
LL | if let (_, _) = mm { }
5959
| ^^ value used here after partial move
6060
|
61-
= note: move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait
61+
= note: partial move occurs because `mm.1` has type `M`, which does not implement the `Copy` trait
6262

6363
error: aborting due to 6 previous errors
6464

src/test/ui/borrowck/borrowck-move-out-from-array-match.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn move_out_from_begin_field_and_end() {
2020
[_, _, (_x, _)] => {}
2121
}
2222
match a {
23-
[.., _y] => {} //~ ERROR use of moved value
23+
[.., _y] => {} //~ ERROR use of partially moved value
2424
}
2525
}
2626

@@ -42,7 +42,7 @@ fn move_out_by_const_index_and_subslice() {
4242
[_x, _, _] => {}
4343
}
4444
match a {
45-
//~^ ERROR use of moved value
45+
//~^ ERROR use of partially moved value
4646
[_y @ .., _, _] => {}
4747
}
4848
}
@@ -53,7 +53,7 @@ fn move_out_by_const_index_end_and_subslice() {
5353
[.., _x] => {}
5454
}
5555
match a {
56-
//~^ ERROR use of moved value
56+
//~^ ERROR use of partially moved value
5757
[_, _, _y @ ..] => {}
5858
}
5959
}
@@ -64,7 +64,7 @@ fn move_out_by_const_index_field_and_subslice() {
6464
[(_x, _), _, _] => {}
6565
}
6666
match a {
67-
//~^ ERROR use of moved value
67+
//~^ ERROR use of partially moved value
6868
[_y @ .., _, _] => {}
6969
}
7070
}
@@ -75,7 +75,7 @@ fn move_out_by_const_index_end_field_and_subslice() {
7575
[.., (_x, _)] => {}
7676
}
7777
match a {
78-
//~^ ERROR use of moved value
78+
//~^ ERROR use of partially moved value
7979
[_, _, _y @ ..] => {}
8080
}
8181
}
@@ -108,7 +108,7 @@ fn move_out_by_subslice_and_subslice() {
108108
[x @ .., _] => {}
109109
}
110110
match a {
111-
//~^ ERROR use of moved value
111+
//~^ ERROR use of partially moved value
112112
[_, _y @ ..] => {}
113113
}
114114
}

0 commit comments

Comments
 (0)