Skip to content

Commit

Permalink
Rollup merge of rust-lang#51057 - pnkfelix:issue-51025-make-ui-tests-…
Browse files Browse the repository at this point in the history
…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 rust-lang#51025
  • Loading branch information
Mark-Simulacrum authored May 26, 2018
2 parents 90b7bf6 + d8bd533 commit b1de351
Show file tree
Hide file tree
Showing 70 changed files with 725 additions and 362 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
error: compilation successful
--> $DIR/borrowck-report-with-custom-diagnostic.rs:12:1
error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-report-with-custom-diagnostic.rs:17:13
|
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
LL | | // Original borrow ends at end of function
LL | | let mut x = 1;
LL | | let y = &mut x;
... |
LL | | //~^ immutable borrow occurs here
LL | | }
| |_^
LL | let y = &mut x;
| ------ mutable borrow occurs here
LL | //~^ mutable borrow occurs here
LL | let z = &x; //~ ERROR cannot borrow
| ^^ immutable borrow occurs here
...
LL | y.use_mut();
| - borrow later used here

error: aborting due to previous error
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-report-with-custom-diagnostic.rs:30:21
|
LL | let y = &x;
| -- immutable borrow occurs here
LL | //~^ immutable borrow occurs here
LL | let z = &mut x; //~ ERROR cannot borrow
| ^^^^^^ mutable borrow occurs here
...
LL | y.use_ref();
| - borrow later used here

error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-report-with-custom-diagnostic.rs:45:17
|
LL | let y = &mut x;
| ------ first mutable borrow occurs here
LL | //~^ first mutable borrow occurs here
LL | let z = &mut x; //~ ERROR cannot borrow
| ^^^^^^ second mutable borrow occurs here
...
LL | y.use_mut();
| - borrow later used here

error: aborting due to 3 previous errors

Some errors occurred: E0499, E0502.
For more information about an error, try `rustc --explain E0499`.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ fn main() { #![rustc_error] // rust-lang/rust#49855
//~^ mutable borrow occurs here
let z = &x; //~ ERROR cannot borrow
//~^ immutable borrow occurs here
z.use_ref();
y.use_mut();
}

fn foo() {
Expand All @@ -27,6 +29,8 @@ fn foo() {
//~^ immutable borrow occurs here
let z = &mut x; //~ ERROR cannot borrow
//~^ mutable borrow occurs here
z.use_mut();
y.use_ref();
}
false => ()
}
Expand All @@ -40,5 +44,10 @@ fn bar() {
//~^ first mutable borrow occurs here
let z = &mut x; //~ ERROR cannot borrow
//~^ second mutable borrow occurs here
z.use_mut();
y.use_mut();
};
}

trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ LL | let y = &mut x;
LL | //~^ mutable borrow occurs here
LL | let z = &x; //~ ERROR cannot borrow
| ^ immutable borrow occurs here
LL | //~^ immutable borrow occurs here
...
LL | }
| - mutable borrow ends here

error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-report-with-custom-diagnostic.rs:28:26
--> $DIR/borrowck-report-with-custom-diagnostic.rs:30:26
|
LL | let y = &x;
| - immutable borrow occurs here
LL | //~^ immutable borrow occurs here
LL | let z = &mut x; //~ ERROR cannot borrow
| ^ mutable borrow occurs here
LL | //~^ mutable borrow occurs here
...
LL | }
| - immutable borrow ends here

error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/borrowck-report-with-custom-diagnostic.rs:41:22
--> $DIR/borrowck-report-with-custom-diagnostic.rs:45:22
|
LL | let y = &mut x;
| - first mutable borrow occurs here
LL | //~^ first mutable borrow occurs here
LL | let z = &mut x; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
LL | //~^ second mutable borrow occurs here
...
LL | };
| - first borrow ends here

Expand Down
32 changes: 21 additions & 11 deletions src/test/ui/borrowck/mut-borrow-outside-loop.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
error: compilation successful
--> $DIR/mut-borrow-outside-loop.rs:13:1
error[E0499]: cannot borrow `void` as mutable more than once at a time
--> $DIR/mut-borrow-outside-loop.rs:17:18
|
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
LL | | let mut void = ();
LL | |
LL | | let first = &mut void;
... |
LL | | }
LL | | }
| |_^
LL | let first = &mut void;
| --------- first mutable borrow occurs here
LL | let second = &mut void; //~ ERROR cannot borrow
| ^^^^^^^^^ second mutable borrow occurs here
LL | first.use_mut();
| ----- borrow later used here

error: aborting due to previous error
error[E0499]: cannot borrow `inner_void` as mutable more than once at a time
--> $DIR/mut-borrow-outside-loop.rs:25:28
|
LL | let inner_first = &mut inner_void;
| --------------- first mutable borrow occurs here
LL | let inner_second = &mut inner_void; //~ ERROR cannot borrow
| ^^^^^^^^^^^^^^^ second mutable borrow occurs here
LL | inner_second.use_mut();
LL | inner_first.use_mut();
| ----------- borrow later used here

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0499`.
6 changes: 6 additions & 0 deletions src/test/ui/borrowck/mut-borrow-outside-loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ fn main() { #![rustc_error] // rust-lang/rust#49855

let first = &mut void;
let second = &mut void; //~ ERROR cannot borrow
first.use_mut();
second.use_mut();

loop {
let mut inner_void = ();

let inner_first = &mut inner_void;
let inner_second = &mut inner_void; //~ ERROR cannot borrow
inner_second.use_mut();
inner_first.use_mut();
}
}

trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
3 changes: 2 additions & 1 deletion src/test/ui/borrowck/mut-borrow-outside-loop.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ LL | }
| - first borrow ends here

error[E0499]: cannot borrow `inner_void` as mutable more than once at a time
--> $DIR/mut-borrow-outside-loop.rs:23:33
--> $DIR/mut-borrow-outside-loop.rs:25:33
|
LL | let inner_first = &mut inner_void;
| ---------- first mutable borrow occurs here
LL | let inner_second = &mut inner_void; //~ ERROR cannot borrow
| ^^^^^^^^^^ second mutable borrow occurs here
...
LL | }
| - first borrow ends here

Expand Down
18 changes: 10 additions & 8 deletions src/test/ui/codemap_tests/issue-11715.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
error: compilation successful
--> $DIR/issue-11715.rs:97:1
error[E0499]: cannot borrow `x` as mutable more than once at a time
--> $DIR/issue-11715.rs:100:13
|
LL | / fn main() { #![rustc_error] // rust-lang/rust#49855
LL | | let mut x = "foo";
LL | | let y = &mut x;
LL | | let z = &mut x; //~ ERROR cannot borrow
LL | | }
| |_^
LL | let y = &mut x;
| ------ first mutable borrow occurs here
LL | let z = &mut x; //~ ERROR cannot borrow
| ^^^^^^ second mutable borrow occurs here
LL | z.use_mut();
LL | y.use_mut();
| - borrow later used here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0499`.
5 changes: 5 additions & 0 deletions src/test/ui/codemap_tests/issue-11715.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ fn main() { #![rustc_error] // rust-lang/rust#49855
let mut x = "foo";
let y = &mut x;
let z = &mut x; //~ ERROR cannot borrow
z.use_mut();
y.use_mut();
}

trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
impl<T> Fake for T { }
1 change: 1 addition & 0 deletions src/test/ui/codemap_tests/issue-11715.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let y = &mut x;
| - first mutable borrow occurs here
LL | let z = &mut x; //~ ERROR cannot borrow
| ^ second mutable borrow occurs here
...
LL | }
| - first borrow ends here

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

error: aborting due to previous error

For more information about this error, try `rustc --explain E0597`.
28 changes: 18 additions & 10 deletions src/test/ui/dropck/dropck-eyepatch-extern-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,41 @@ use other::{Dt,Dr,Pt,Pr,St,Sr};
fn main() { #![rustc_error] // rust-lang/rust#49855
use std::cell::Cell;
let c_long;
let (c, mut dt, mut dr, mut pt, mut pr, st, sr)
: (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>);
let (c, mut dt, mut dr, mut pt, mut pr, st, sr, c_shortest)
: (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>, Cell<_>);
c_long = Cell::new(1);
c = Cell::new(1);
c_shortest = Cell::new(1);

// No error: sufficiently long-lived state can be referenced in dtors
dt = Dt("dt", &c_long);
dr = Dr("dr", &c_long);

// Error: destructor order imprecisely modelled
dt = Dt("dt", &c);
//~^ ERROR `c` does not live long enough
dr = Dr("dr", &c);
//~^ ERROR `c` does not live long enough

// Error: `c_shortest` dies too soon for the references in dtors to be valid.
dt = Dt("dt", &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
dr = Dr("dr", &c_shortest);
//~^ ERROR `c_shortest` does not live long enough

// No error: Drop impl asserts .1 (A and &'a _) are not accessed
pt = Pt("pt", &c, &c_long);
pr = Pr("pr", &c, &c_long);
pt = Pt("pt", &c_shortest, &c_long);
pr = Pr("pr", &c_shortest, &c_long);

// Error: Drop impl's assertion does not apply to `B` nor `&'b _`
pt = Pt("pt", &c_long, &c);
//~^ ERROR `c` does not live long enough
pr = Pr("pr", &c_long, &c);
//~^ ERROR `c` does not live long enough
pt = Pt("pt", &c_long, &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
pr = Pr("pr", &c_long, &c_shortest);
//~^ ERROR `c_shortest` does not live long enough

// No error: St and Sr have no destructor.
st = St("st", &c);
sr = Sr("sr", &c);
st = St("st", &c_shortest);
sr = Sr("sr", &c_shortest);

println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
}
48 changes: 35 additions & 13 deletions src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:39:20
--> $DIR/dropck-eyepatch-extern-crate.rs:41:20
|
LL | dt = Dt("dt", &c);
| ^ borrowed value does not live long enough
Expand All @@ -10,7 +10,7 @@ LL | }
= note: values in a scope are dropped in the opposite order they are created

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

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

error[E0597]: `c` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:51:29
error[E0597]: `c_shortest` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:49:20
|
LL | pr = Pr("pr", &c_long, &c);
| ^ borrowed value does not live long enough
LL | dr = Dr("dr", &c_shortest);
| ^^^^^^^^^^ borrowed value does not live long enough
...
LL | }
| - `c` dropped here while still borrowed
| - `c_shortest` dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are created

error[E0597]: `c_shortest` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:57:29
|
LL | pt = Pt("pt", &c_long, &c_shortest);
| ^^^^^^^^^^ borrowed value does not live long enough
...
LL | }
| - `c_shortest` dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are created

error[E0597]: `c_shortest` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:59:29
|
LL | pr = Pr("pr", &c_long, &c_shortest);
| ^^^^^^^^^^ borrowed value does not live long enough
...
LL | }
| - `c_shortest` dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are created

error: aborting due to 4 previous errors
error: aborting due to 6 previous errors

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

0 comments on commit b1de351

Please sign in to comment.