Skip to content

Commit

Permalink
Auto merge of rust-lang#55221 - matthewjasper:fewer-duplicate-migrate…
Browse files Browse the repository at this point in the history
…-messages, r=pnkfelix

Don't emit cannot move errors twice in migrate mode

Closes rust-lang#55154
cc rust-lang#53004

r? @pnkfelix
  • Loading branch information
bors committed Oct 30, 2018
2 parents fb2446a + 42a541e commit b1ca390
Show file tree
Hide file tree
Showing 44 changed files with 48 additions and 822 deletions.
14 changes: 8 additions & 6 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,7 +1831,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
| Write(wk @ WriteKind::StorageDeadOrDrop)
| Write(wk @ WriteKind::MutableBorrow(BorrowKind::Shared))
| Write(wk @ WriteKind::MutableBorrow(BorrowKind::Shallow)) => {
if let Err(_place_err) = self.is_mutable(place, is_local_mutation_allowed) {
if let (Err(_place_err), true) = (
self.is_mutable(place, is_local_mutation_allowed),
self.errors_buffer.is_empty()
) {
if self.infcx.tcx.migrate_borrowck() {
// rust-lang/rust#46908: In pure NLL mode this
// code path should be unreachable (and thus
Expand All @@ -1855,12 +1858,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
location,
);
} else {
self.infcx.tcx.sess.delay_span_bug(
span_bug!(
span,
&format!(
"Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
place, kind
),
"Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
place,
kind,
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/borrow_check/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
AccessKind::Move => {
err = self.infcx.tcx
.cannot_move_out_of(span, &(item_msg + &reason), Origin::Mir);
act = "move";
acted_on = "moved";
span
err.span_label(span, "cannot move");
err.buffer(&mut self.errors_buffer);
return;
}
AccessKind::Mutate => {
err = self.infcx.tcx
Expand Down
14 changes: 1 addition & 13 deletions src/test/ui/access-mode-in-closures.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ note: move occurs because `v` has type `std::vec::Vec<isize>`, which does not im
LL | match *s { sty(v) => v } //~ ERROR cannot move out
| ^

error[E0507]: cannot move out of `s.0` which is behind a `&` reference
--> $DIR/access-mode-in-closures.rs:19:24
|
LL | let _foo = unpack(|s| {
| - help: consider changing this to be a mutable reference: `&mut sty`
LL | // Test that `s` is moved here.
LL | match *s { sty(v) => v } //~ ERROR cannot move out
| ^
| |
| cannot move out of `s.0` which is behind a `&` reference
| `s` is a `&` reference, so the data it refers to cannot be moved

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.
14 changes: 1 addition & 13 deletions src/test/ui/binop/binop-move-semantics.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ error[E0507]: cannot move out of borrowed content
LL | *n; //~ ERROR: cannot move out of borrowed content
| ^^ cannot move out of borrowed content

error[E0507]: cannot move out of `*n` which is behind a `&` reference
--> $DIR/binop-move-semantics.rs:42:5
|
LL | let n = &y;
| -- help: consider changing this to be a mutable reference: `&mut y`
...
LL | *n; //~ ERROR: cannot move out of borrowed content
| ^^
| |
| cannot move out of `*n` which is behind a `&` reference
| `n` is a `&` reference, so the data it refers to cannot be moved

error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable
--> $DIR/binop-move-semantics.rs:64:5
|
Expand Down Expand Up @@ -74,7 +62,7 @@ LL | | &mut f; //~ ERROR: cannot borrow `f` as mutable because it is also b
| | immutable borrow later used here
| mutable borrow occurs here

error: aborting due to 7 previous errors
error: aborting due to 6 previous errors

Some errors occurred: E0382, E0502, E0507.
For more information about an error, try `rustc --explain E0382`.
20 changes: 0 additions & 20 deletions src/test/ui/borrowck/borrowck-fn-in-const-a.ast.nll.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
error[E0507]: cannot move out of `*__next` which is behind a `&` reference
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:22:10
|
LL | for &a in x.iter() { //~ ERROR cannot move out
| -^
| ||
| |cannot move out of `*__next` which is behind a `&` reference
| |`__next` is a `&` reference, so the data it refers to cannot be moved
| help: consider changing this to be a mutable reference: `&mut a`

error[E0507]: cannot move out of borrowed content
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:22:15
|
Expand All @@ -23,16 +13,6 @@ note: move occurs because `a` has type `&mut i32`, which does not implement the
LL | for &a in x.iter() { //~ ERROR cannot move out
| ^

error[E0507]: cannot move out of `*__next` which is behind a `&` reference
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:28:10
|
LL | for &a in &f.a { //~ ERROR cannot move out
| -^
| ||
| |cannot move out of `*__next` which is behind a `&` reference
| |`__next` is a `&` reference, so the data it refers to cannot be moved
| help: consider changing this to be a mutable reference: `&mut a`

error[E0507]: cannot move out of borrowed content
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:28:15
|
Expand All @@ -48,16 +28,6 @@ note: move occurs because `a` has type `std::boxed::Box<isize>`, which does not
LL | for &a in &f.a { //~ ERROR cannot move out
| ^

error[E0507]: cannot move out of `*__next` which is behind a `&` reference
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:32:10
|
LL | for &a in x.iter() { //~ ERROR cannot move out
| -^
| ||
| |cannot move out of `*__next` which is behind a `&` reference
| |`__next` is a `&` reference, so the data it refers to cannot be moved
| help: consider changing this to be a mutable reference: `&mut a`

error[E0507]: cannot move out of borrowed content
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:32:15
|
Expand All @@ -73,6 +43,6 @@ note: move occurs because `a` has type `std::boxed::Box<i32>`, which does not im
LL | for &a in x.iter() { //~ ERROR cannot move out
| ^

error: aborting due to 6 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0507`.
17 changes: 1 addition & 16 deletions src/test/ui/borrowck/borrowck-in-static.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,6 @@ LL | let x = Box::new(0);
LL | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
| ^ cannot move out of captured variable in an `Fn` closure

error[E0507]: cannot move out of `x`, as it is a captured variable in a `Fn` closure
--> $DIR/borrowck-in-static.rs:15:17
|
LL | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
| ^
| |
| cannot move out of `x`, as it is a captured variable in a `Fn` closure
| cannot move
|
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrowck-in-static.rs:15:14
|
LL | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
| ^^^^

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.
13 changes: 1 addition & 12 deletions src/test/ui/borrowck/borrowck-issue-2657-2.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ LL | let _b = *y; //~ ERROR cannot move out
| cannot move out of borrowed content
| help: consider removing the `*`: `y`

error[E0507]: cannot move out of `*y` which is behind a `&` reference
--> $DIR/borrowck-issue-2657-2.rs:17:18
|
LL | Some(ref y) => {
| ----- help: consider changing this to be a mutable reference: `ref mut y`
LL | let _b = *y; //~ ERROR cannot move out
| ^^
| |
| cannot move out of `*y` which is behind a `&` reference
| `y` is a `&` reference, so the data it refers to cannot be moved

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.
14 changes: 0 additions & 14 deletions src/test/ui/borrowck/borrowck-migrate-to-nll.edition.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,3 @@ LL | (|| { let bar = foo; bar.take() })();
It represents potential unsoundness in your code.
This warning will become a hard error in the future.

warning[E0507]: cannot move out of `foo`, as it is immutable for the pattern guard
--> $DIR/borrowck-migrate-to-nll.rs:35:17
|
LL | (|| { let bar = foo; bar.take() })();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| cannot move out of `foo`, as it is immutable for the pattern guard
| cannot move
|
= note: variables bound in patterns are immutable until the end of the pattern guard
= warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
It represents potential unsoundness in your code.
This warning will become a hard error in the future.

14 changes: 0 additions & 14 deletions src/test/ui/borrowck/borrowck-migrate-to-nll.zflag.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,3 @@ LL | (|| { let bar = foo; bar.take() })();
It represents potential unsoundness in your code.
This warning will become a hard error in the future.

warning[E0507]: cannot move out of `foo`, as it is immutable for the pattern guard
--> $DIR/borrowck-migrate-to-nll.rs:35:17
|
LL | (|| { let bar = foo; bar.take() })();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| cannot move out of `foo`, as it is immutable for the pattern guard
| cannot move
|
= note: variables bound in patterns are immutable until the end of the pattern guard
= warning: This error has been downgraded to a warning for backwards compatibility with previous releases.
It represents potential unsoundness in your code.
This warning will become a hard error in the future.

50 changes: 1 addition & 49 deletions src/test/ui/borrowck/borrowck-move-error-with-note.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,6 @@ LL | num2) => (),
LL | Foo::Foo2(num) => (),
| ^^^

error[E0507]: cannot move out of `f.0` which is behind a `&` reference
--> $DIR/borrowck-move-error-with-note.rs:23:19
|
LL | let f = &Foo::Foo1(box 1, box 2);
| ------------------------ help: consider changing this to be a mutable reference: `&mut Foo::Foo1(box 1, box 2)`
...
LL | Foo::Foo1(num1,
| ^^^^
| |
| cannot move out of `f.0` which is behind a `&` reference
| `f` is a `&` reference, so the data it refers to cannot be moved

error[E0507]: cannot move out of `f.1` which is behind a `&` reference
--> $DIR/borrowck-move-error-with-note.rs:24:19
|
LL | let f = &Foo::Foo1(box 1, box 2);
| ------------------------ help: consider changing this to be a mutable reference: `&mut Foo::Foo1(box 1, box 2)`
...
LL | num2) => (),
| ^^^^
| |
| cannot move out of `f.1` which is behind a `&` reference
| `f` is a `&` reference, so the data it refers to cannot be moved

error[E0507]: cannot move out of `f.0` which is behind a `&` reference
--> $DIR/borrowck-move-error-with-note.rs:25:19
|
LL | let f = &Foo::Foo1(box 1, box 2);
| ------------------------ help: consider changing this to be a mutable reference: `&mut Foo::Foo1(box 1, box 2)`
...
LL | Foo::Foo2(num) => (),
| ^^^
| |
| cannot move out of `f.0` which is behind a `&` reference
| `f` is a `&` reference, so the data it refers to cannot be moved

error[E0509]: cannot move out of type `S`, which implements the `Drop` trait
--> $DIR/borrowck-move-error-with-note.rs:39:11
|
Expand Down Expand Up @@ -97,19 +61,7 @@ note: move occurs because `n` has type `std::boxed::Box<isize>`, which does not
LL | n => {
| ^

error[E0507]: cannot move out of `a.a` which is behind a `&` reference
--> $DIR/borrowck-move-error-with-note.rs:59:9
|
LL | let a = &A { a: box 1 };
| --------------- help: consider changing this to be a mutable reference: `&mut A { a: box 1 }`
...
LL | n => {
| ^
| |
| cannot move out of `a.a` which is behind a `&` reference
| `a` is a `&` reference, so the data it refers to cannot be moved

error: aborting due to 7 previous errors
error: aborting due to 3 previous errors

Some errors occurred: E0507, E0509.
For more information about an error, try `rustc --explain E0507`.
13 changes: 1 addition & 12 deletions src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer
| cannot move out of dereference of raw pointer
| help: consider removing the `*`: `x`

error[E0507]: cannot move out of `*x` which is behind a `*const` pointer
--> $DIR/borrowck-move-from-unsafe-ptr.rs:13:13
|
LL | unsafe fn foo(x: *const Box<isize>) -> Box<isize> {
| ----------------- help: consider changing this to be a mutable pointer: `*mut std::boxed::Box<isize>`
LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer
| ^^
| |
| cannot move out of `*x` which is behind a `*const` pointer
| `x` is a `*const` pointer, so the data it refers to cannot be moved

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.
29 changes: 1 addition & 28 deletions src/test/ui/borrowck/borrowck-move-in-irrefut-pat.ast.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ note: move occurs because `_x` has type `std::string::String`, which does not im
LL | fn arg_item(&_x: &String) {}
| ^^

error[E0507]: cannot move out of data in a `&` reference
--> $DIR/borrowck-move-in-irrefut-pat.rs:16:14
|
LL | fn arg_item(&_x: &String) {}
| ^^
| |
| cannot move out of data in a `&` reference
| cannot move

error[E0507]: cannot move out of borrowed content
--> $DIR/borrowck-move-in-irrefut-pat.rs:21:11
|
Expand All @@ -39,24 +30,6 @@ note: move occurs because `_x` has type `std::string::String`, which does not im
LL | with(|&_x| ())
| ^^

error[E0507]: cannot move out of data in a `&` reference
--> $DIR/borrowck-move-in-irrefut-pat.rs:21:12
|
LL | with(|&_x| ())
| ^^
| |
| cannot move out of data in a `&` reference
| cannot move

error[E0507]: cannot move out of data in a `&` reference
--> $DIR/borrowck-move-in-irrefut-pat.rs:27:10
|
LL | let &_x = &"hi".to_string();
| ^^
| |
| cannot move out of data in a `&` reference
| cannot move

error[E0507]: cannot move out of borrowed content
--> $DIR/borrowck-move-in-irrefut-pat.rs:27:15
|
Expand All @@ -72,6 +45,6 @@ note: move occurs because `_x` has type `std::string::String`, which does not im
LL | let &_x = &"hi".to_string();
| ^^

error: aborting due to 6 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0507`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ error[E0507]: cannot move out of an `Rc`
LL | let _x = Rc::new(vec![1, 2]).into_iter();
| ^^^^^^^^^^^^^^^^^^^ cannot move out of an `Rc`

error[E0507]: cannot move out of data in a `&` reference
--> $DIR/borrowck-move-out-of-overloaded-auto-deref.rs:17:14
|
LL | let _x = Rc::new(vec![1, 2]).into_iter();
| ^^^^^^^^^^^^^^^^^^^
| |
| cannot move out of data in a `&` reference
| cannot move

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0507`.
Loading

0 comments on commit b1ca390

Please sign in to comment.