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

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

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

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

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

+2-1
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

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

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

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

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`.

src/test/ui/dropck/dropck-eyepatch-extern-crate.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,41 @@ use other::{Dt,Dr,Pt,Pr,St,Sr};
2727
fn main() { #![rustc_error] // rust-lang/rust#49855
2828
use std::cell::Cell;
2929
let c_long;
30-
let (c, mut dt, mut dr, mut pt, mut pr, st, sr)
31-
: (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>);
30+
let (c, mut dt, mut dr, mut pt, mut pr, st, sr, c_shortest)
31+
: (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>, Cell<_>);
3232
c_long = Cell::new(1);
3333
c = Cell::new(1);
34+
c_shortest = Cell::new(1);
3435

3536
// No error: sufficiently long-lived state can be referenced in dtors
3637
dt = Dt("dt", &c_long);
3738
dr = Dr("dr", &c_long);
39+
3840
// Error: destructor order imprecisely modelled
3941
dt = Dt("dt", &c);
4042
//~^ ERROR `c` does not live long enough
4143
dr = Dr("dr", &c);
4244
//~^ ERROR `c` does not live long enough
4345

46+
// Error: `c_shortest` dies too soon for the references in dtors to be valid.
47+
dt = Dt("dt", &c_shortest);
48+
//~^ ERROR `c_shortest` does not live long enough
49+
dr = Dr("dr", &c_shortest);
50+
//~^ ERROR `c_shortest` does not live long enough
51+
4452
// No error: Drop impl asserts .1 (A and &'a _) are not accessed
45-
pt = Pt("pt", &c, &c_long);
46-
pr = Pr("pr", &c, &c_long);
53+
pt = Pt("pt", &c_shortest, &c_long);
54+
pr = Pr("pr", &c_shortest, &c_long);
4755

4856
// Error: Drop impl's assertion does not apply to `B` nor `&'b _`
49-
pt = Pt("pt", &c_long, &c);
50-
//~^ ERROR `c` does not live long enough
51-
pr = Pr("pr", &c_long, &c);
52-
//~^ ERROR `c` does not live long enough
57+
pt = Pt("pt", &c_long, &c_shortest);
58+
//~^ ERROR `c_shortest` does not live long enough
59+
pr = Pr("pr", &c_long, &c_shortest);
60+
//~^ ERROR `c_shortest` does not live long enough
5361

5462
// No error: St and Sr have no destructor.
55-
st = St("st", &c);
56-
sr = Sr("sr", &c);
63+
st = St("st", &c_shortest);
64+
sr = Sr("sr", &c_shortest);
5765

5866
println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
5967
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0597]: `c` does not live long enough
2-
--> $DIR/dropck-eyepatch-extern-crate.rs:39:20
2+
--> $DIR/dropck-eyepatch-extern-crate.rs:41:20
33
|
44
LL | dt = Dt("dt", &c);
55
| ^ borrowed value does not live long enough
@@ -10,7 +10,7 @@ LL | }
1010
= note: values in a scope are dropped in the opposite order they are created
1111

1212
error[E0597]: `c` does not live long enough
13-
--> $DIR/dropck-eyepatch-extern-crate.rs:41:20
13+
--> $DIR/dropck-eyepatch-extern-crate.rs:43:20
1414
|
1515
LL | dr = Dr("dr", &c);
1616
| ^ borrowed value does not live long enough
@@ -20,28 +20,50 @@ LL | }
2020
|
2121
= note: values in a scope are dropped in the opposite order they are created
2222

23-
error[E0597]: `c` does not live long enough
24-
--> $DIR/dropck-eyepatch-extern-crate.rs:49:29
23+
error[E0597]: `c_shortest` does not live long enough
24+
--> $DIR/dropck-eyepatch-extern-crate.rs:47:20
2525
|
26-
LL | pt = Pt("pt", &c_long, &c);
27-
| ^ borrowed value does not live long enough
26+
LL | dt = Dt("dt", &c_shortest);
27+
| ^^^^^^^^^^ borrowed value does not live long enough
2828
...
2929
LL | }
30-
| - `c` dropped here while still borrowed
30+
| - `c_shortest` dropped here while still borrowed
3131
|
3232
= note: values in a scope are dropped in the opposite order they are created
3333

34-
error[E0597]: `c` does not live long enough
35-
--> $DIR/dropck-eyepatch-extern-crate.rs:51:29
34+
error[E0597]: `c_shortest` does not live long enough
35+
--> $DIR/dropck-eyepatch-extern-crate.rs:49:20
3636
|
37-
LL | pr = Pr("pr", &c_long, &c);
38-
| ^ borrowed value does not live long enough
37+
LL | dr = Dr("dr", &c_shortest);
38+
| ^^^^^^^^^^ borrowed value does not live long enough
3939
...
4040
LL | }
41-
| - `c` dropped here while still borrowed
41+
| - `c_shortest` dropped here while still borrowed
42+
|
43+
= note: values in a scope are dropped in the opposite order they are created
44+
45+
error[E0597]: `c_shortest` does not live long enough
46+
--> $DIR/dropck-eyepatch-extern-crate.rs:57:29
47+
|
48+
LL | pt = Pt("pt", &c_long, &c_shortest);
49+
| ^^^^^^^^^^ borrowed value does not live long enough
50+
...
51+
LL | }
52+
| - `c_shortest` dropped here while still borrowed
53+
|
54+
= note: values in a scope are dropped in the opposite order they are created
55+
56+
error[E0597]: `c_shortest` does not live long enough
57+
--> $DIR/dropck-eyepatch-extern-crate.rs:59:29
58+
|
59+
LL | pr = Pr("pr", &c_long, &c_shortest);
60+
| ^^^^^^^^^^ borrowed value does not live long enough
61+
...
62+
LL | }
63+
| - `c_shortest` dropped here while still borrowed
4264
|
4365
= note: values in a scope are dropped in the opposite order they are created
4466

45-
error: aborting due to 4 previous errors
67+
error: aborting due to 6 previous errors
4668

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

0 commit comments

Comments
 (0)