fix closure tests now that MIR typeck works properly

These tests had FIXMEs for errors that were not previously being
reported.
This commit is contained in:
Niko Matsakis 2017-12-07 06:25:59 -05:00
parent decbbb3fc0
commit a30e2259da
12 changed files with 145 additions and 82 deletions

View File

@ -27,7 +27,8 @@ fn main() {
let mut x = 22;
{
let p = &x; //~ ERROR borrowed value does not live long enough
let p = &x;
//~^ ERROR `x` does not live long enough
let w = Foo { t: p };
let v = [w; 22];
@ -36,4 +37,3 @@ fn main() {
x += 1;
//~^ ERROR cannot assign to `x` because it is borrowed [E0506]
}
//~^ ERROR borrowed value does not live long enough [E0597]

View File

@ -24,11 +24,10 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
fn error(u: &(), v: &()) {
static_id(&u); //[ll]~ ERROR cannot infer an appropriate lifetime
//[nll]~^ WARNING not reporting region error due to -Znll
//[nll]~| ERROR free region `'_#1r` does not outlive free region `'static`
static_id_indirect(&v); //[ll]~ ERROR cannot infer an appropriate lifetime
//[nll]~^ WARNING not reporting region error due to -Znll
// FIXME(#45827) -- MIR type checker shortcomings mean we don't
// see these errors (yet) in nll mode.
//[nll]~| ERROR free region `'_#2r` does not outlive free region `'static`
}
fn main() {}

View File

@ -21,14 +21,8 @@
//
// Note: the use of `Cell` here is to introduce invariance. One less
// variable.
//
// FIXME(#45827): The `supply` function *ought* to generate an error, but it
// currently does not. This is I believe a shortcoming of the MIR type
// checker: the closure inference is expressing the correct
// requirement, as you can see from the `#[rustc_regions]` output.
// compile-flags:-Znll -Zborrowck=mir -Zverbose
// must-compile-successfully
#![feature(rustc_attrs)]
@ -57,8 +51,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
//~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
// Only works if 'x: 'y:
demand_y(x, y, x.get())
demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
});
}

View File

@ -1,17 +1,19 @@
warning: not reporting region error due to -Znll
--> $DIR/propagate-approximated-ref.rs:61:9
--> $DIR/propagate-approximated-ref.rs:57:9
|
61 | demand_y(x, y, x.get())
57 | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
| ^^^^^^^^^^^^^^^^^^^^^^^
note: External requirements
--> $DIR/propagate-approximated-ref.rs:59:47
--> $DIR/propagate-approximated-ref.rs:53:47
|
59 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
60 | | // Only works if 'x: 'y:
61 | | demand_y(x, y, x.get())
62 | | });
54 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
55 | |
56 | | // Only works if 'x: 'y:
57 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
58 | | });
| |_____^
|
= note: defining type: DefId(0/1:18 ~ propagate_approximated_ref[317d]::supply[0]::{{closure}}[0]) with closure substs [
@ -21,16 +23,25 @@ note: External requirements
= note: number of external vids: 3
= note: where '_#1r: '_#2r
note: No external requirements
--> $DIR/propagate-approximated-ref.rs:58:1
error: free region `'_#1r` does not outlive free region `'_#2r`
--> $DIR/propagate-approximated-ref.rs:53:38
|
58 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
59 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
60 | | // Only works if 'x: 'y:
61 | | demand_y(x, y, x.get())
62 | | });
63 | | }
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| ^^^^^^^
note: No external requirements
--> $DIR/propagate-approximated-ref.rs:52:1
|
52 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
53 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
54 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
55 | |
... |
58 | | });
59 | | }
| |_^
|
= note: defining type: DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]) with substs []
error: aborting due to previous error

View File

@ -39,12 +39,10 @@ fn case1() {
fn case2() {
let a = 0;
let cell = Cell::new(&a);
//~^ ERROR `a` does not live long enough
// As you can see in the stderr output, this closure propoagates a
// requirement that `'a: 'static'.
//
// FIXME(#45827) However, because of shortcomings in the MIR type
// checker, this does not result in errors later on (yet).
foo(cell, |cell_a, cell_x| {
cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
})

View File

@ -42,12 +42,12 @@ note: No external requirements
= note: defining type: DefId(0/0:5 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]) with substs []
note: External requirements
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:48:15
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:46:15
|
48 | foo(cell, |cell_a, cell_x| {
46 | foo(cell, |cell_a, cell_x| {
| _______________^
49 | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
50 | | })
47 | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
48 | | })
| |_____^
|
= note: defining type: DefId(0/1:13 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [
@ -63,13 +63,24 @@ note: No external requirements
39 | / fn case2() {
40 | | let a = 0;
41 | | let cell = Cell::new(&a);
42 | |
42 | | //~^ ERROR `a` does not live long enough
... |
50 | | })
51 | | }
48 | | })
49 | | }
| |_^
|
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]) with substs []
error: aborting due to previous error
error[E0597]: `a` does not live long enough
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:41:26
|
41 | let cell = Cell::new(&a);
| ^^ does not live long enough
...
49 | }
| - borrowed value only lives until here
|
= note: borrowed value must be valid for lifetime '_#1r...
error: aborting due to 2 previous errors

View File

@ -17,7 +17,6 @@
// these errors are not (yet) reported.
// compile-flags:-Znll -Zborrowck=mir -Zverbose
// must-compile-successfully
#![feature(rustc_attrs)]
@ -44,8 +43,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
//~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
// Only works if 'x: 'y:
demand_y(x, y, x.get())
demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
});
}

View File

@ -1,17 +1,19 @@
warning: not reporting region error due to -Znll
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:48:9
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:49:9
|
48 | demand_y(x, y, x.get())
49 | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
| ^^^^^^^^^^^^^^^^^^^^^^^
note: External requirements
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:46:47
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
|
46 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
| _______________________________________________^
47 | | // Only works if 'x: 'y:
48 | | demand_y(x, y, x.get())
49 | | });
46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
47 | |
48 | | // Only works if 'x: 'y:
49 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
50 | | });
| |_____^
|
= note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
@ -21,16 +23,31 @@ note: External requirements
= note: number of external vids: 2
= note: where '_#1r: '_#0r
note: No external requirements
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:1
error: free region `'_#1r` does not outlive free region `ReStatic`
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
|
45 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
46 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
47 | | // Only works if 'x: 'y:
48 | | demand_y(x, y, x.get())
49 | | });
50 | | }
45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
| _______________________________________________^
46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
47 | |
48 | | // Only works if 'x: 'y:
49 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
50 | | });
| |_____^
note: No external requirements
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1
|
44 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
45 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
47 | |
... |
50 | | });
51 | | }
| |_^
|
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []
error: aborting due to previous error

View File

@ -18,7 +18,6 @@
// these errors are not (yet) reported.
// compile-flags:-Znll -Zborrowck=mir -Zverbose
// must-compile-successfully
#![feature(rustc_attrs)]
@ -47,8 +46,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
//~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ WARNING not reporting region error due to -Znll
});
}

View File

@ -5,13 +5,15 @@ warning: not reporting region error due to -Znll
| ^^^^^^^^^^^^^^^^^^^^^^^
note: External requirements
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:49:47
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
|
49 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
48 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
50 | | // Only works if 'x: 'y:
51 | | demand_y(x, y, x.get())
52 | | });
52 | | //~^ WARNING not reporting region error due to -Znll
53 | | });
| |_____^
|
= note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
@ -21,16 +23,31 @@ note: External requirements
= note: number of external vids: 3
= note: where '_#1r: '_#0r
note: No external requirements
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:1
error: free region `'_#1r` does not outlive free region `ReStatic`
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
|
48 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
49 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
48 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
50 | | // Only works if 'x: 'y:
51 | | demand_y(x, y, x.get())
52 | | });
53 | | }
52 | | //~^ WARNING not reporting region error due to -Znll
53 | | });
| |_____^
note: No external requirements
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1
|
47 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
48 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
50 | | // Only works if 'x: 'y:
... |
53 | | });
54 | | }
| |_^
|
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []
error: aborting due to previous error

View File

@ -16,7 +16,6 @@
// anonymous regions as well.
// compile-flags:-Znll -Zborrowck=mir -Zverbose
// must-compile-successfully
#![feature(rustc_attrs)]
@ -45,8 +44,10 @@ fn demand_y<'x, 'y>(_outlives1: Cell<&&'x u32>, _outlives2: Cell<&'y &u32>, _y:
#[rustc_regions]
fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
//~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
// Only works if 'x: 'y:
demand_y(outlives1, outlives2, x.get())
demand_y(outlives1, outlives2, x.get()) //~ WARNING not reporting region error due to -Znll
});
}

View File

@ -1,17 +1,19 @@
warning: not reporting region error due to -Znll
--> $DIR/propagate-approximated-val.rs:49:9
--> $DIR/propagate-approximated-val.rs:50:9
|
49 | demand_y(outlives1, outlives2, x.get())
50 | demand_y(outlives1, outlives2, x.get()) //~ WARNING not reporting region error due to -Znll
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: External requirements
--> $DIR/propagate-approximated-val.rs:47:45
--> $DIR/propagate-approximated-val.rs:46:45
|
47 | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
46 | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
| _____________________________________________^
48 | | // Only works if 'x: 'y:
49 | | demand_y(outlives1, outlives2, x.get())
50 | | });
47 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
48 | |
49 | | // Only works if 'x: 'y:
50 | | demand_y(outlives1, outlives2, x.get()) //~ WARNING not reporting region error due to -Znll
51 | | });
| |_____^
|
= note: defining type: DefId(0/1:18 ~ propagate_approximated_val[317d]::test[0]::{{closure}}[0]) with closure substs [
@ -21,16 +23,25 @@ note: External requirements
= note: number of external vids: 3
= note: where '_#1r: '_#2r
note: No external requirements
--> $DIR/propagate-approximated-val.rs:46:1
error: free region `'_#1r` does not outlive free region `'_#2r`
--> $DIR/propagate-approximated-val.rs:46:37
|
46 | / fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
47 | | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
48 | | // Only works if 'x: 'y:
49 | | demand_y(outlives1, outlives2, x.get())
50 | | });
51 | | }
46 | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
| ^^^^^^
note: No external requirements
--> $DIR/propagate-approximated-val.rs:45:1
|
45 | / fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
46 | | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
47 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
48 | |
... |
51 | | });
52 | | }
| |_^
|
= note: defining type: DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]) with substs []
error: aborting due to previous error