Skip to content

Commit b1ca390

Browse files
committed
Auto merge of #55221 - matthewjasper:fewer-duplicate-migrate-messages, r=pnkfelix
Don't emit cannot move errors twice in migrate mode Closes #55154 cc #53004 r? @pnkfelix
2 parents fb2446a + 42a541e commit b1ca390

File tree

44 files changed

+48
-822
lines changed

Some content is hidden

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

44 files changed

+48
-822
lines changed

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

+8-6
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
}

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

+3-3
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

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

+1-13
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`.

Diff for: src/test/ui/binop/binop-move-semantics.nll.stderr

+1-13
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`.

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

-20
This file was deleted.
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`.

Diff for: src/test/ui/borrowck/borrowck-in-static.nll.stderr

+1-16
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`.

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

+1-12
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`.

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

-14
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-

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

-14
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-

Diff for: src/test/ui/borrowck/borrowck-move-error-with-note.nll.stderr

+1-49
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,6 @@ LL | num2) => (),
2424
LL | Foo::Foo2(num) => (),
2525
| ^^^
2626

27-
error[E0507]: cannot move out of `f.0` which is behind a `&` reference
28-
--> $DIR/borrowck-move-error-with-note.rs:23:19
29-
|
30-
LL | let f = &Foo::Foo1(box 1, box 2);
31-
| ------------------------ help: consider changing this to be a mutable reference: `&mut Foo::Foo1(box 1, box 2)`
32-
...
33-
LL | Foo::Foo1(num1,
34-
| ^^^^
35-
| |
36-
| cannot move out of `f.0` which is behind a `&` reference
37-
| `f` is a `&` reference, so the data it refers to cannot be moved
38-
39-
error[E0507]: cannot move out of `f.1` which is behind a `&` reference
40-
--> $DIR/borrowck-move-error-with-note.rs:24:19
41-
|
42-
LL | let f = &Foo::Foo1(box 1, box 2);
43-
| ------------------------ help: consider changing this to be a mutable reference: `&mut Foo::Foo1(box 1, box 2)`
44-
...
45-
LL | num2) => (),
46-
| ^^^^
47-
| |
48-
| cannot move out of `f.1` which is behind a `&` reference
49-
| `f` is a `&` reference, so the data it refers to cannot be moved
50-
51-
error[E0507]: cannot move out of `f.0` which is behind a `&` reference
52-
--> $DIR/borrowck-move-error-with-note.rs:25:19
53-
|
54-
LL | let f = &Foo::Foo1(box 1, box 2);
55-
| ------------------------ help: consider changing this to be a mutable reference: `&mut Foo::Foo1(box 1, box 2)`
56-
...
57-
LL | Foo::Foo2(num) => (),
58-
| ^^^
59-
| |
60-
| cannot move out of `f.0` which is behind a `&` reference
61-
| `f` is a `&` reference, so the data it refers to cannot be moved
62-
6327
error[E0509]: cannot move out of type `S`, which implements the `Drop` trait
6428
--> $DIR/borrowck-move-error-with-note.rs:39:11
6529
|
@@ -97,19 +61,7 @@ note: move occurs because `n` has type `std::boxed::Box<isize>`, which does not
9761
LL | n => {
9862
| ^
9963

100-
error[E0507]: cannot move out of `a.a` which is behind a `&` reference
101-
--> $DIR/borrowck-move-error-with-note.rs:59:9
102-
|
103-
LL | let a = &A { a: box 1 };
104-
| --------------- help: consider changing this to be a mutable reference: `&mut A { a: box 1 }`
105-
...
106-
LL | n => {
107-
| ^
108-
| |
109-
| cannot move out of `a.a` which is behind a `&` reference
110-
| `a` is a `&` reference, so the data it refers to cannot be moved
111-
112-
error: aborting due to 7 previous errors
64+
error: aborting due to 3 previous errors
11365

11466
Some errors occurred: E0507, E0509.
11567
For more information about an error, try `rustc --explain E0507`.

Diff for: src/test/ui/borrowck/borrowck-move-from-unsafe-ptr.nll.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer
77
| cannot move out of dereference of raw pointer
88
| help: consider removing the `*`: `x`
99

10-
error[E0507]: cannot move out of `*x` which is behind a `*const` pointer
11-
--> $DIR/borrowck-move-from-unsafe-ptr.rs:13:13
12-
|
13-
LL | unsafe fn foo(x: *const Box<isize>) -> Box<isize> {
14-
| ----------------- help: consider changing this to be a mutable pointer: `*mut std::boxed::Box<isize>`
15-
LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer
16-
| ^^
17-
| |
18-
| cannot move out of `*x` which is behind a `*const` pointer
19-
| `x` is a `*const` pointer, 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`.

Diff for: src/test/ui/borrowck/borrowck-move-in-irrefut-pat.ast.nll.stderr

+1-28
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ note: move occurs because `_x` has type `std::string::String`, which does not im
1414
LL | fn arg_item(&_x: &String) {}
1515
| ^^
1616

17-
error[E0507]: cannot move out of data in a `&` reference
18-
--> $DIR/borrowck-move-in-irrefut-pat.rs:16:14
19-
|
20-
LL | fn arg_item(&_x: &String) {}
21-
| ^^
22-
| |
23-
| cannot move out of data in a `&` reference
24-
| cannot move
25-
2617
error[E0507]: cannot move out of borrowed content
2718
--> $DIR/borrowck-move-in-irrefut-pat.rs:21:11
2819
|
@@ -39,24 +30,6 @@ note: move occurs because `_x` has type `std::string::String`, which does not im
3930
LL | with(|&_x| ())
4031
| ^^
4132

42-
error[E0507]: cannot move out of data in a `&` reference
43-
--> $DIR/borrowck-move-in-irrefut-pat.rs:21:12
44-
|
45-
LL | with(|&_x| ())
46-
| ^^
47-
| |
48-
| cannot move out of data in a `&` reference
49-
| cannot move
50-
51-
error[E0507]: cannot move out of data in a `&` reference
52-
--> $DIR/borrowck-move-in-irrefut-pat.rs:27:10
53-
|
54-
LL | let &_x = &"hi".to_string();
55-
| ^^
56-
| |
57-
| cannot move out of data in a `&` reference
58-
| cannot move
59-
6033
error[E0507]: cannot move out of borrowed content
6134
--> $DIR/borrowck-move-in-irrefut-pat.rs:27:15
6235
|
@@ -72,6 +45,6 @@ note: move occurs because `_x` has type `std::string::String`, which does not im
7245
LL | let &_x = &"hi".to_string();
7346
| ^^
7447

75-
error: aborting due to 6 previous errors
48+
error: aborting due to 3 previous errors
7649

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

Diff for: src/test/ui/borrowck/borrowck-move-out-of-overloaded-auto-deref.ast.nll.stderr

+1-10
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,6 @@ error[E0507]: cannot move out of an `Rc`
44
LL | let _x = Rc::new(vec![1, 2]).into_iter();
55
| ^^^^^^^^^^^^^^^^^^^ cannot move out of an `Rc`
66

7-
error[E0507]: cannot move out of data in a `&` reference
8-
--> $DIR/borrowck-move-out-of-overloaded-auto-deref.rs:17:14
9-
|
10-
LL | let _x = Rc::new(vec![1, 2]).into_iter();
11-
| ^^^^^^^^^^^^^^^^^^^
12-
| |
13-
| cannot move out of data in a `&` reference
14-
| cannot move
15-
16-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
178

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

0 commit comments

Comments
 (0)