Skip to content

Commit b1de351

Browse files
Rollup merge of #51057 - pnkfelix:issue-51025-make-ui-tests-robust-wrt-nll, r=nikomatsakis
make ui tests robust with respect to NLL This PR revises the `ui` tests that I could quickly identify that: 1. previously had successful compilations under non-lexical lifetimes (NLL) because they assumed lexical lifetimes, but 2. such assumption of lexical lifetimes was actually not necessarily part of the spirit of the original issue/bug we want to witness. In many cases, this is simply a matter of adding a use of a borrow so that it gets extended long enough to observe a conflict. (In some cases the revision was more subtle, such as adding a destructor, or revising the order of declaration of some variables.) ---- With these test revisions in place, I subsequently updated the expected stderr output under the NLL compiletest mode. So now we should get even more testing of NLL than we were before. Fix #51025
2 parents 90b7bf6 + d8bd533 commit b1de351

File tree

70 files changed

+725
-362
lines changed

Some content is hidden

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

70 files changed

+725
-362
lines changed
Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
1-
error: compilation successful
2-
--> $DIR/borrowck-report-with-custom-diagnostic.rs:12:1
1+
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
2+
--> $DIR/borrowck-report-with-custom-diagnostic.rs:17:13
33
|
4-
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
5-
LL | | // Original borrow ends at end of function
6-
LL | | let mut x = 1;
7-
LL | | let y = &mut x;
8-
... |
9-
LL | | //~^ immutable borrow occurs here
10-
LL | | }
11-
| |_^
4+
LL | let y = &mut x;
5+
| ------ mutable borrow occurs here
6+
LL | //~^ mutable borrow occurs here
7+
LL | let z = &x; //~ ERROR cannot borrow
8+
| ^^ immutable borrow occurs here
9+
...
10+
LL | y.use_mut();
11+
| - borrow later used here
1212

13-
error: aborting due to previous error
13+
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
14+
--> $DIR/borrowck-report-with-custom-diagnostic.rs:30:21
15+
|
16+
LL | let y = &x;
17+
| -- immutable borrow occurs here
18+
LL | //~^ immutable borrow occurs here
19+
LL | let z = &mut x; //~ ERROR cannot borrow
20+
| ^^^^^^ mutable borrow occurs here
21+
...
22+
LL | y.use_ref();
23+
| - borrow later used here
24+
25+
error[E0499]: cannot borrow `x` as mutable more than once at a time
26+
--> $DIR/borrowck-report-with-custom-diagnostic.rs:45:17
27+
|
28+
LL | let y = &mut x;
29+
| ------ first mutable borrow occurs here
30+
LL | //~^ first mutable borrow occurs here
31+
LL | let z = &mut x; //~ ERROR cannot borrow
32+
| ^^^^^^ second mutable borrow occurs here
33+
...
34+
LL | y.use_mut();
35+
| - borrow later used here
36+
37+
error: aborting due to 3 previous errors
1438

39+
Some errors occurred: E0499, E0502.
40+
For more information about an error, try `rustc --explain E0499`.

src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ fn main() { #![rustc_error] // rust-lang/rust#49855
1616
//~^ mutable borrow occurs here
1717
let z = &x; //~ ERROR cannot borrow
1818
//~^ immutable borrow occurs here
19+
z.use_ref();
20+
y.use_mut();
1921
}
2022

2123
fn foo() {
@@ -27,6 +29,8 @@ fn foo() {
2729
//~^ immutable borrow occurs here
2830
let z = &mut x; //~ ERROR cannot borrow
2931
//~^ mutable borrow occurs here
32+
z.use_mut();
33+
y.use_ref();
3034
}
3135
false => ()
3236
}
@@ -40,5 +44,10 @@ fn bar() {
4044
//~^ first mutable borrow occurs here
4145
let z = &mut x; //~ ERROR cannot borrow
4246
//~^ second mutable borrow occurs here
47+
z.use_mut();
48+
y.use_mut();
4349
};
4450
}
51+
52+
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
53+
impl<T> Fake for T { }

src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,31 @@ LL | let y = &mut x;
66
LL | //~^ mutable borrow occurs here
77
LL | let z = &x; //~ ERROR cannot borrow
88
| ^ immutable borrow occurs here
9-
LL | //~^ immutable borrow occurs here
9+
...
1010
LL | }
1111
| - mutable borrow ends here
1212

1313
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
14-
--> $DIR/borrowck-report-with-custom-diagnostic.rs:28:26
14+
--> $DIR/borrowck-report-with-custom-diagnostic.rs:30:26
1515
|
1616
LL | let y = &x;
1717
| - immutable borrow occurs here
1818
LL | //~^ immutable borrow occurs here
1919
LL | let z = &mut x; //~ ERROR cannot borrow
2020
| ^ mutable borrow occurs here
21-
LL | //~^ mutable borrow occurs here
21+
...
2222
LL | }
2323
| - immutable borrow ends here
2424

2525
error[E0499]: cannot borrow `x` as mutable more than once at a time
26-
--> $DIR/borrowck-report-with-custom-diagnostic.rs:41:22
26+
--> $DIR/borrowck-report-with-custom-diagnostic.rs:45:22
2727
|
2828
LL | let y = &mut x;
2929
| - first mutable borrow occurs here
3030
LL | //~^ first mutable borrow occurs here
3131
LL | let z = &mut x; //~ ERROR cannot borrow
3232
| ^ second mutable borrow occurs here
33-
LL | //~^ second mutable borrow occurs here
33+
...
3434
LL | };
3535
| - first borrow ends here
3636

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
error: compilation successful
2-
--> $DIR/mut-borrow-outside-loop.rs:13:1
1+
error[E0499]: cannot borrow `void` as mutable more than once at a time
2+
--> $DIR/mut-borrow-outside-loop.rs:17:18
33
|
4-
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
5-
LL | | let mut void = ();
6-
LL | |
7-
LL | | let first = &mut void;
8-
... |
9-
LL | | }
10-
LL | | }
11-
| |_^
4+
LL | let first = &mut void;
5+
| --------- first mutable borrow occurs here
6+
LL | let second = &mut void; //~ ERROR cannot borrow
7+
| ^^^^^^^^^ second mutable borrow occurs here
8+
LL | first.use_mut();
9+
| ----- borrow later used here
1210

13-
error: aborting due to previous error
11+
error[E0499]: cannot borrow `inner_void` as mutable more than once at a time
12+
--> $DIR/mut-borrow-outside-loop.rs:25:28
13+
|
14+
LL | let inner_first = &mut inner_void;
15+
| --------------- first mutable borrow occurs here
16+
LL | let inner_second = &mut inner_void; //~ ERROR cannot borrow
17+
| ^^^^^^^^^^^^^^^ second mutable borrow occurs here
18+
LL | inner_second.use_mut();
19+
LL | inner_first.use_mut();
20+
| ----------- borrow later used here
21+
22+
error: aborting due to 2 previous errors
1423

24+
For more information about this error, try `rustc --explain E0499`.

src/test/ui/borrowck/mut-borrow-outside-loop.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ fn main() { #![rustc_error] // rust-lang/rust#49855
1515

1616
let first = &mut void;
1717
let second = &mut void; //~ ERROR cannot borrow
18+
first.use_mut();
19+
second.use_mut();
1820

1921
loop {
2022
let mut inner_void = ();
2123

2224
let inner_first = &mut inner_void;
2325
let inner_second = &mut inner_void; //~ ERROR cannot borrow
26+
inner_second.use_mut();
27+
inner_first.use_mut();
2428
}
2529
}
2630

31+
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
32+
impl<T> Fake for T { }

src/test/ui/borrowck/mut-borrow-outside-loop.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ LL | }
1010
| - first borrow ends here
1111

1212
error[E0499]: cannot borrow `inner_void` as mutable more than once at a time
13-
--> $DIR/mut-borrow-outside-loop.rs:23:33
13+
--> $DIR/mut-borrow-outside-loop.rs:25:33
1414
|
1515
LL | let inner_first = &mut inner_void;
1616
| ---------- first mutable borrow occurs here
1717
LL | let inner_second = &mut inner_void; //~ ERROR cannot borrow
1818
| ^^^^^^^^^^ second mutable borrow occurs here
19+
...
1920
LL | }
2021
| - first borrow ends here
2122

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
error: compilation successful
2-
--> $DIR/issue-11715.rs:97:1
1+
error[E0499]: cannot borrow `x` as mutable more than once at a time
2+
--> $DIR/issue-11715.rs:100:13
33
|
4-
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
5-
LL | | let mut x = "foo";
6-
LL | | let y = &mut x;
7-
LL | | let z = &mut x; //~ ERROR cannot borrow
8-
LL | | }
9-
| |_^
4+
LL | let y = &mut x;
5+
| ------ first mutable borrow occurs here
6+
LL | let z = &mut x; //~ ERROR cannot borrow
7+
| ^^^^^^ second mutable borrow occurs here
8+
LL | z.use_mut();
9+
LL | y.use_mut();
10+
| - borrow later used here
1011

1112
error: aborting due to previous error
1213

14+
For more information about this error, try `rustc --explain E0499`.

src/test/ui/codemap_tests/issue-11715.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@ fn main() { #![rustc_error] // rust-lang/rust#49855
9898
let mut x = "foo";
9999
let y = &mut x;
100100
let z = &mut x; //~ ERROR cannot borrow
101+
z.use_mut();
102+
y.use_mut();
101103
}
104+
105+
trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
106+
impl<T> Fake for T { }

src/test/ui/codemap_tests/issue-11715.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | let y = &mut x;
55
| - first mutable borrow occurs here
66
LL | let z = &mut x; //~ ERROR cannot borrow
77
| ^ second mutable borrow occurs here
8+
...
89
LL | }
910
| - first borrow ends here
1011

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
error: compilation successful
2-
--> $DIR/dropck-eyepatch-extern-crate.rs:27:1
1+
error[E0597]: `c_shortest` does not live long enough
2+
--> $DIR/dropck-eyepatch-extern-crate.rs:47:19
33
|
4-
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
5-
LL | | use std::cell::Cell;
6-
LL | | let c_long;
7-
LL | | let (c, mut dt, mut dr, mut pt, mut pr, st, sr)
8-
... |
9-
LL | | println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
10-
LL | | }
11-
| |_^
4+
LL | dt = Dt("dt", &c_shortest);
5+
| ^^^^^^^^^^^ borrowed value does not live long enough
6+
...
7+
LL | }
8+
| -
9+
| |
10+
| borrowed value only lives until here
11+
| borrow later used here, when `dt` is dropped
1212

1313
error: aborting due to previous error
1414

15+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)