Skip to content

Commit 8220be5

Browse files
committed
Use revisions for NLL in borrowck
1 parent 1e435e3 commit 8220be5

6 files changed

+121
-26
lines changed

src/test/ui/borrowck/borrowck-reborrow-from-shorter-lived-andmut.stderr renamed to src/test/ui/borrowck/borrowck-reborrow-from-shorter-lived-andmut.base.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0623]: lifetime mismatch
2-
--> $DIR/borrowck-reborrow-from-shorter-lived-andmut.rs:9:5
2+
--> $DIR/borrowck-reborrow-from-shorter-lived-andmut.rs:13:5
33
|
44
LL | fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
55
| ------------- -----

src/test/ui/borrowck/borrowck-reborrow-from-shorter-lived-andmut.nll.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime may not live long enough
2-
--> $DIR/borrowck-reborrow-from-shorter-lived-andmut.rs:9:5
2+
--> $DIR/borrowck-reborrow-from-shorter-lived-andmut.rs:13:5
33
|
44
LL | fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
55
| -- -- lifetime `'b` defined here

src/test/ui/borrowck/borrowck-reborrow-from-shorter-lived-andmut.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// ignore-compare-mode-nll
2+
// revisions: base nll
3+
// [nll]compile-flags: -Zborrowck=mir
4+
15
// Test that assignments to an `&mut` pointer which is found in a
26
// borrowed (but otherwise non-aliasable) location is illegal.
37

@@ -7,7 +11,8 @@ struct S<'a> {
711

812
fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
913
S { pointer: &mut *p.pointer }
10-
//~^ ERROR lifetime mismatch
14+
//[base]~^ ERROR lifetime mismatch
15+
//[nll]~^^ ERROR lifetime may not live long enough
1116
}
1217

1318
fn main() {
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
error[E0499]: cannot borrow `*f` as mutable more than once at a time
2+
--> $DIR/two-phase-nonrecv-autoref.rs:51:11
3+
|
4+
LL | f(f(10));
5+
| - ^ second mutable borrow occurs here
6+
| |
7+
| first mutable borrow occurs here
8+
| first borrow later used by call
9+
10+
error[E0382]: use of moved value: `f`
11+
--> $DIR/two-phase-nonrecv-autoref.rs:58:11
12+
|
13+
LL | fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
14+
| - move occurs because `f` has type `Box<F>`, which does not implement the `Copy` trait
15+
LL | f(f(10));
16+
| - ^ value used here after move
17+
| |
18+
| value moved here
19+
20+
error[E0499]: cannot borrow `*f` as mutable more than once at a time
21+
--> $DIR/two-phase-nonrecv-autoref.rs:63:11
22+
|
23+
LL | f(f(10));
24+
| - ^ second mutable borrow occurs here
25+
| |
26+
| first mutable borrow occurs here
27+
| first borrow later used by call
28+
29+
error[E0382]: use of moved value: `f`
30+
--> $DIR/two-phase-nonrecv-autoref.rs:70:11
31+
|
32+
LL | fn twice_ten_oo(f: Box<dyn FnOnce(i32) -> i32>) {
33+
| - move occurs because `f` has type `Box<dyn FnOnce(i32) -> i32>`, which does not implement the `Copy` trait
34+
LL | f(f(10));
35+
| - ^ value used here after move
36+
| |
37+
| value moved here
38+
39+
error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
40+
--> $DIR/two-phase-nonrecv-autoref.rs:108:27
41+
|
42+
LL | double_access(&mut a, &a);
43+
| ------------- ------ ^^ immutable borrow occurs here
44+
| | |
45+
| | mutable borrow occurs here
46+
| mutable borrow later used by call
47+
48+
error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
49+
--> $DIR/two-phase-nonrecv-autoref.rs:133:7
50+
|
51+
LL | i[i[3]] = 4;
52+
| --^----
53+
| | |
54+
| | immutable borrow occurs here
55+
| mutable borrow occurs here
56+
| mutable borrow later used here
57+
|
58+
help: try adding a local storing this...
59+
--> $DIR/two-phase-nonrecv-autoref.rs:133:7
60+
|
61+
LL | i[i[3]] = 4;
62+
| ^^^^
63+
help: ...and then using that local here
64+
--> $DIR/two-phase-nonrecv-autoref.rs:133:5
65+
|
66+
LL | i[i[3]] = 4;
67+
| ^^^^^^^
68+
69+
error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
70+
--> $DIR/two-phase-nonrecv-autoref.rs:139:7
71+
|
72+
LL | i[i[3]] = i[4];
73+
| --^----
74+
| | |
75+
| | immutable borrow occurs here
76+
| mutable borrow occurs here
77+
| mutable borrow later used here
78+
|
79+
help: try adding a local storing this...
80+
--> $DIR/two-phase-nonrecv-autoref.rs:139:7
81+
|
82+
LL | i[i[3]] = i[4];
83+
| ^^^^
84+
help: ...and then using that local here
85+
--> $DIR/two-phase-nonrecv-autoref.rs:139:5
86+
|
87+
LL | i[i[3]] = i[4];
88+
| ^^^^^^^
89+
90+
error: aborting due to 7 previous errors
91+
92+
Some errors have detailed explanations: E0382, E0499, E0502.
93+
For more information about an error, try `rustc --explain E0382`.

src/test/ui/borrowck/two-phase-nonrecv-autoref.nll.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | f(f(10));
88
| first borrow later used by call
99

1010
error[E0382]: use of moved value: `f`
11-
--> $DIR/two-phase-nonrecv-autoref.rs:59:11
11+
--> $DIR/two-phase-nonrecv-autoref.rs:58:11
1212
|
1313
LL | fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
1414
| - move occurs because `f` has type `Box<F>`, which does not implement the `Copy` trait
@@ -18,7 +18,7 @@ LL | f(f(10));
1818
| value moved here
1919

2020
error[E0499]: cannot borrow `*f` as mutable more than once at a time
21-
--> $DIR/two-phase-nonrecv-autoref.rs:65:11
21+
--> $DIR/two-phase-nonrecv-autoref.rs:63:11
2222
|
2323
LL | f(f(10));
2424
| - ^ second mutable borrow occurs here
@@ -27,7 +27,7 @@ LL | f(f(10));
2727
| first borrow later used by call
2828

2929
error[E0382]: use of moved value: `f`
30-
--> $DIR/two-phase-nonrecv-autoref.rs:73:11
30+
--> $DIR/two-phase-nonrecv-autoref.rs:70:11
3131
|
3232
LL | fn twice_ten_oo(f: Box<dyn FnOnce(i32) -> i32>) {
3333
| - move occurs because `f` has type `Box<dyn FnOnce(i32) -> i32>`, which does not implement the `Copy` trait
@@ -37,7 +37,7 @@ LL | f(f(10));
3737
| value moved here
3838

3939
error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
40-
--> $DIR/two-phase-nonrecv-autoref.rs:112:27
40+
--> $DIR/two-phase-nonrecv-autoref.rs:108:27
4141
|
4242
LL | double_access(&mut a, &a);
4343
| ------------- ------ ^^ immutable borrow occurs here
@@ -46,7 +46,7 @@ LL | double_access(&mut a, &a);
4646
| mutable borrow later used by call
4747

4848
error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
49-
--> $DIR/two-phase-nonrecv-autoref.rs:138:7
49+
--> $DIR/two-phase-nonrecv-autoref.rs:133:7
5050
|
5151
LL | i[i[3]] = 4;
5252
| --^----
@@ -56,18 +56,18 @@ LL | i[i[3]] = 4;
5656
| mutable borrow later used here
5757
|
5858
help: try adding a local storing this...
59-
--> $DIR/two-phase-nonrecv-autoref.rs:138:7
59+
--> $DIR/two-phase-nonrecv-autoref.rs:133:7
6060
|
6161
LL | i[i[3]] = 4;
6262
| ^^^^
6363
help: ...and then using that local here
64-
--> $DIR/two-phase-nonrecv-autoref.rs:138:5
64+
--> $DIR/two-phase-nonrecv-autoref.rs:133:5
6565
|
6666
LL | i[i[3]] = 4;
6767
| ^^^^^^^
6868

6969
error[E0502]: cannot borrow `i` as immutable because it is also borrowed as mutable
70-
--> $DIR/two-phase-nonrecv-autoref.rs:143:7
70+
--> $DIR/two-phase-nonrecv-autoref.rs:139:7
7171
|
7272
LL | i[i[3]] = i[4];
7373
| --^----
@@ -77,12 +77,12 @@ LL | i[i[3]] = i[4];
7777
| mutable borrow later used here
7878
|
7979
help: try adding a local storing this...
80-
--> $DIR/two-phase-nonrecv-autoref.rs:143:7
80+
--> $DIR/two-phase-nonrecv-autoref.rs:139:7
8181
|
8282
LL | i[i[3]] = i[4];
8383
| ^^^^
8484
help: ...and then using that local here
85-
--> $DIR/two-phase-nonrecv-autoref.rs:143:5
85+
--> $DIR/two-phase-nonrecv-autoref.rs:139:5
8686
|
8787
LL | i[i[3]] = i[4];
8888
| ^^^^^^^

src/test/ui/borrowck/two-phase-nonrecv-autoref.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// revisions: nll
1+
// revisions: base nll
22
//[nll]compile-flags: -Z borrowck=mir
33

44
//[g2p]compile-flags: -Z borrowck=mir -Z two-phase-beyond-autoref
@@ -49,30 +49,26 @@ fn overloaded_call_traits() {
4949

5050
fn twice_ten_sm<F: FnMut(i32) -> i32>(f: &mut F) {
5151
f(f(10));
52-
//[nll]~^ ERROR cannot borrow `*f` as mutable more than once at a time
53-
//[g2p]~^^ ERROR cannot borrow `*f` as mutable more than once at a time
52+
//~^ ERROR cannot borrow `*f` as mutable more than once at a time
5453
}
5554
fn twice_ten_si<F: Fn(i32) -> i32>(f: &mut F) {
5655
f(f(10));
5756
}
5857
fn twice_ten_so<F: FnOnce(i32) -> i32>(f: Box<F>) {
5958
f(f(10));
60-
//[nll]~^ ERROR use of moved value: `f`
61-
//[g2p]~^^ ERROR use of moved value: `f`
59+
//~^ ERROR use of moved value: `f`
6260
}
6361

6462
fn twice_ten_om(f: &mut dyn FnMut(i32) -> i32) {
6563
f(f(10));
66-
//[nll]~^ ERROR cannot borrow `*f` as mutable more than once at a time
67-
//[g2p]~^^ ERROR cannot borrow `*f` as mutable more than once at a time
64+
//~^ ERROR cannot borrow `*f` as mutable more than once at a time
6865
}
6966
fn twice_ten_oi(f: &mut dyn Fn(i32) -> i32) {
7067
f(f(10));
7168
}
7269
fn twice_ten_oo(f: Box<dyn FnOnce(i32) -> i32>) {
7370
f(f(10));
74-
//[nll]~^ ERROR use of moved value: `f`
75-
//[g2p]~^^ ERROR use of moved value: `f`
71+
//~^ ERROR use of moved value: `f`
7672
}
7773

7874
twice_ten_sm(&mut |x| x + 1);
@@ -110,8 +106,7 @@ fn coerce_unsized() {
110106

111107
// This is not okay.
112108
double_access(&mut a, &a);
113-
//[nll]~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable [E0502]
114-
//[g2p]~^^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable [E0502]
109+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable [E0502]
115110

116111
// But this is okay.
117112
a.m(a.i(10));
@@ -136,12 +131,14 @@ impl IndexMut<i32> for I {
136131
fn coerce_index_op() {
137132
let mut i = I(10);
138133
i[i[3]] = 4;
139-
//[nll]~^ ERROR cannot borrow `i` as immutable because it is also borrowed as mutable [E0502]
134+
//~^ ERROR cannot borrow `i` as immutable because it is also borrowed as mutable [E0502]
135+
// Shoud be accepted with g2p
140136

141137
i[3] = i[4];
142138

143139
i[i[3]] = i[4];
144-
//[nll]~^ ERROR cannot borrow `i` as immutable because it is also borrowed as mutable [E0502]
140+
//~^ ERROR cannot borrow `i` as immutable because it is also borrowed as mutable [E0502]
141+
// Shoud be accepted with g2p
145142
}
146143

147144
fn main() {

0 commit comments

Comments
 (0)