Skip to content

Commit

Permalink
Rollup merge of rust-lang#58199 - clintfred:partial-move-err-msg, r=e…
Browse files Browse the repository at this point in the history
…stebank

Add better error message for partial move

closes rust-lang#56657

r? @davidtwco
  • Loading branch information
Centril authored Feb 23, 2019
2 parents 6bf3c18 + 02fe6a7 commit 8f8aa9b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/librustc_mir/borrow_check/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
);

let mut is_loop_move = false;
let is_partial_move = move_site_vec.iter().any(|move_site| {
let move_out = self.move_data.moves[(*move_site).moi];
let moved_place = &self.move_data.move_paths[move_out.path].place;
used_place != moved_place && used_place.is_prefix_of(moved_place)
});
for move_site in &move_site_vec {
let move_out = self.move_data.moves[(*move_site).moi];
let moved_place = &self.move_data.move_paths[move_out.path].place;
Expand Down Expand Up @@ -175,8 +180,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
err.span_label(
span,
format!(
"value {} here after move",
desired_action.as_verb_in_past_tense()
"value {} here {}",
desired_action.as_verb_in_past_tense(),
if is_partial_move { "after partial move" } else { "after move" },
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ error[E0382]: use of moved value: `line2`
LL | let _moved = (line2.origin, line2.middle);
| ------------ value moved here
LL | line2.consume(); //[ast]~ ERROR use of partially moved value: `line2` [E0382]
| ^^^^^ value used here after move
| ^^^^^ value used here after partial move
|
= note: move occurs because `line2.middle` has type `Point`, which does not implement the `Copy` trait

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ error[E0382]: use of moved value: `line2`
LL | let _moved = (line2.origin, line2.middle);
| ------------ value moved here
LL | line2.consume(); //[ast]~ ERROR use of partially moved value: `line2` [E0382]
| ^^^^^ value used here after move
| ^^^^^ value used here after partial move
|
= note: move occurs because `line2.middle` has type `Point`, which does not implement the `Copy` trait

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | Some(right) => consume(right),
| ----- value moved here
...
LL | consume(node) + r //~ ERROR use of partially moved value: `node`
| ^^^^ value used here after move
| ^^^^ value used here after partial move
|
= note: move occurs because value has type `std::boxed::Box<List>`, which does not implement the `Copy` trait

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | Foo {f} => {}
| - value moved here
...
LL | touch(&x); //~ ERROR use of partially moved value: `x`
| ^^ value borrowed here after move
| ^^ value borrowed here after partial move
|
= note: move occurs because `x.f` has type `std::string::String`, which does not implement the `Copy` trait

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/nll/move-subpaths-moves-root.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0382]: use of moved value: `x`
LL | drop(x.0);
| --- value moved here
LL | drop(x); //~ ERROR use of moved value
| ^ value used here after move
| ^ value used here after partial move
|
= note: move occurs because `x.0` has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/ref-suggestion.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LL | (Some(y), ()) => {},
| - value moved here
...
LL | x; //~ ERROR use of partially moved value
| ^ value used here after move
| ^ value used here after partial move
|
= note: move occurs because value has type `std::vec::Vec<i32>`, which does not implement the `Copy` trait

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/unsized-locals/borrow-after-move.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | let y = *x;
| -- value moved here
LL | drop_unsized(y);
LL | println!("{}", &x);
| ^^ value borrowed here after move
| ^^ value borrowed here after partial move
|
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait

Expand All @@ -27,7 +27,7 @@ LL | let y = *x;
| -- value moved here
LL | y.foo();
LL | println!("{}", &x);
| ^^ value borrowed here after move
| ^^ value borrowed here after partial move
|
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait

Expand All @@ -48,7 +48,7 @@ error[E0382]: borrow of moved value: `x`
LL | x.foo();
| - value moved here
LL | println!("{}", &x);
| ^^ value borrowed here after move
| ^^ value borrowed here after partial move
|
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/unsized-locals/double-move.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ error[E0382]: use of moved value: `x`
LL | let _y = *x;
| -- value moved here
LL | drop_unsized(x); //~ERROR use of moved value
| ^ value used here after move
| ^ value used here after partial move
|
= note: move occurs because `*x` has type `str`, which does not implement the `Copy` trait

Expand Down

0 comments on commit 8f8aa9b

Please sign in to comment.