Skip to content

Commit 5f1fd68

Browse files
authored
Rollup merge of rust-lang#55221 - matthewjasper:fewer-duplicate-migrate-messages, r=pnkfelix
Don't emit cannot move errors twice in migrate mode Closes rust-lang#55154 cc rust-lang#53004 r? @pnkfelix
2 parents 9f59c45 + b375728 commit 5f1fd68

File tree

43 files changed

+46
-810
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+46
-810
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,10 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18311831
| Write(wk @ WriteKind::StorageDeadOrDrop)
18321832
| Write(wk @ WriteKind::MutableBorrow(BorrowKind::Shared))
18331833
| Write(wk @ WriteKind::MutableBorrow(BorrowKind::Shallow)) => {
1834-
if let Err(_place_err) = self.is_mutable(place, is_local_mutation_allowed) {
1834+
if let (Err(_place_err), true) = (
1835+
self.is_mutable(place, is_local_mutation_allowed),
1836+
self.errors_buffer.is_empty()
1837+
) {
18351838
if self.infcx.tcx.migrate_borrowck() {
18361839
// rust-lang/rust#46908: In pure NLL mode this
18371840
// code path should be unreachable (and thus
@@ -1855,12 +1858,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18551858
location,
18561859
);
18571860
} else {
1858-
self.infcx.tcx.sess.delay_span_bug(
1861+
span_bug!(
18591862
span,
1860-
&format!(
1861-
"Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
1862-
place, kind
1863-
),
1863+
"Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
1864+
place,
1865+
kind,
18641866
);
18651867
}
18661868
}

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
180180
AccessKind::Move => {
181181
err = self.infcx.tcx
182182
.cannot_move_out_of(span, &(item_msg + &reason), Origin::Mir);
183-
act = "move";
184-
acted_on = "moved";
185-
span
183+
err.span_label(span, "cannot move");
184+
err.buffer(&mut self.errors_buffer);
185+
return;
186186
}
187187
AccessKind::Mutate => {
188188
err = self.infcx.tcx

src/test/ui/access-mode-in-closures.nll.stderr

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,6 @@ note: move occurs because `v` has type `std::vec::Vec<isize>`, which does not im
1313
LL | match *s { sty(v) => v } //~ ERROR cannot move out
1414
| ^
1515

16-
error[E0507]: cannot move out of `s.0` which is behind a `&` reference
17-
--> $DIR/access-mode-in-closures.rs:19:24
18-
|
19-
LL | let _foo = unpack(|s| {
20-
| - help: consider changing this to be a mutable reference: `&mut sty`
21-
LL | // Test that `s` is moved here.
22-
LL | match *s { sty(v) => v } //~ ERROR cannot move out
23-
| ^
24-
| |
25-
| cannot move out of `s.0` which is behind a `&` reference
26-
| `s` is a `&` reference, so the data it refers to cannot be moved
27-
28-
error: aborting due to 2 previous errors
16+
error: aborting due to previous error
2917

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

src/test/ui/binop/binop-move-semantics.nll.stderr

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ error[E0507]: cannot move out of borrowed content
3232
LL | *n; //~ ERROR: cannot move out of borrowed content
3333
| ^^ cannot move out of borrowed content
3434

35-
error[E0507]: cannot move out of `*n` which is behind a `&` reference
36-
--> $DIR/binop-move-semantics.rs:42:5
37-
|
38-
LL | let n = &y;
39-
| -- help: consider changing this to be a mutable reference: `&mut y`
40-
...
41-
LL | *n; //~ ERROR: cannot move out of borrowed content
42-
| ^^
43-
| |
44-
| cannot move out of `*n` which is behind a `&` reference
45-
| `n` is a `&` reference, so the data it refers to cannot be moved
46-
4735
error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable
4836
--> $DIR/binop-move-semantics.rs:64:5
4937
|
@@ -74,7 +62,7 @@ LL | | &mut f; //~ ERROR: cannot borrow `f` as mutable because it is also b
7462
| | immutable borrow later used here
7563
| mutable borrow occurs here
7664

77-
error: aborting due to 7 previous errors
65+
error: aborting due to 6 previous errors
7866

7967
Some errors occurred: E0382, E0502, E0507.
8068
For more information about an error, try `rustc --explain E0382`.

src/test/ui/borrowck/borrowck-fn-in-const-a.ast.nll.stderr

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
error[E0507]: cannot move out of `*__next` which is behind a `&` reference
2-
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:22:10
3-
|
4-
LL | for &a in x.iter() { //~ ERROR cannot move out
5-
| -^
6-
| ||
7-
| |cannot move out of `*__next` which is behind a `&` reference
8-
| |`__next` is a `&` reference, so the data it refers to cannot be moved
9-
| help: consider changing this to be a mutable reference: `&mut a`
10-
111
error[E0507]: cannot move out of borrowed content
122
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:22:15
133
|
@@ -23,16 +13,6 @@ note: move occurs because `a` has type `&mut i32`, which does not implement the
2313
LL | for &a in x.iter() { //~ ERROR cannot move out
2414
| ^
2515

26-
error[E0507]: cannot move out of `*__next` which is behind a `&` reference
27-
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:28:10
28-
|
29-
LL | for &a in &f.a { //~ ERROR cannot move out
30-
| -^
31-
| ||
32-
| |cannot move out of `*__next` which is behind a `&` reference
33-
| |`__next` is a `&` reference, so the data it refers to cannot be moved
34-
| help: consider changing this to be a mutable reference: `&mut a`
35-
3616
error[E0507]: cannot move out of borrowed content
3717
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:28:15
3818
|
@@ -48,16 +28,6 @@ note: move occurs because `a` has type `std::boxed::Box<isize>`, which does not
4828
LL | for &a in &f.a { //~ ERROR cannot move out
4929
| ^
5030

51-
error[E0507]: cannot move out of `*__next` which is behind a `&` reference
52-
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:32:10
53-
|
54-
LL | for &a in x.iter() { //~ ERROR cannot move out
55-
| -^
56-
| ||
57-
| |cannot move out of `*__next` which is behind a `&` reference
58-
| |`__next` is a `&` reference, so the data it refers to cannot be moved
59-
| help: consider changing this to be a mutable reference: `&mut a`
60-
6131
error[E0507]: cannot move out of borrowed content
6232
--> $DIR/borrowck-for-loop-correct-cmt-for-pattern.rs:32:15
6333
|
@@ -73,6 +43,6 @@ note: move occurs because `a` has type `std::boxed::Box<i32>`, which does not im
7343
LL | for &a in x.iter() { //~ ERROR cannot move out
7444
| ^
7545

76-
error: aborting due to 6 previous errors
46+
error: aborting due to 3 previous errors
7747

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

src/test/ui/borrowck/borrowck-in-static.nll.stderr

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,6 @@ LL | let x = Box::new(0);
66
LL | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
77
| ^ cannot move out of captured variable in an `Fn` closure
88

9-
error[E0507]: cannot move out of `x`, as it is a captured variable in a `Fn` closure
10-
--> $DIR/borrowck-in-static.rs:15:17
11-
|
12-
LL | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
13-
| ^
14-
| |
15-
| cannot move out of `x`, as it is a captured variable in a `Fn` closure
16-
| cannot move
17-
|
18-
help: consider changing this to accept closures that implement `FnMut`
19-
--> $DIR/borrowck-in-static.rs:15:14
20-
|
21-
LL | Box::new(|| x) //~ ERROR cannot move out of captured outer variable
22-
| ^^^^
23-
24-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
2510

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

src/test/ui/borrowck/borrowck-issue-2657-2.nll.stderr

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ LL | let _b = *y; //~ ERROR cannot move out
77
| cannot move out of borrowed content
88
| help: consider removing the `*`: `y`
99

10-
error[E0507]: cannot move out of `*y` which is behind a `&` reference
11-
--> $DIR/borrowck-issue-2657-2.rs:17:18
12-
|
13-
LL | Some(ref y) => {
14-
| ----- help: consider changing this to be a mutable reference: `ref mut y`
15-
LL | let _b = *y; //~ ERROR cannot move out
16-
| ^^
17-
| |
18-
| cannot move out of `*y` which is behind a `&` reference
19-
| `y` is a `&` reference, so the data it refers to cannot be moved
20-
21-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
2211

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

src/test/ui/borrowck/borrowck-migrate-to-nll.edition.stderr

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,3 @@ LL | (|| { let bar = foo; bar.take() })();
88
It represents potential unsoundness in your code.
99
This warning will become a hard error in the future.
1010

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

src/test/ui/borrowck/borrowck-migrate-to-nll.zflag.stderr

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,3 @@ LL | (|| { let bar = foo; bar.take() })();
88
It represents potential unsoundness in your code.
99
This warning will become a hard error in the future.
1010

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

0 commit comments

Comments
 (0)