Skip to content

Commit

Permalink
fix closure tests now that MIR typeck works properly
Browse files Browse the repository at this point in the history
These tests had FIXMEs for errors that were not previously being
reported.
  • Loading branch information
nikomatsakis committed Dec 2, 2017
1 parent da45109 commit 3eb4284
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
//
// Note: the use of `Cell` here is to introduce invariance. One less
// variable.
//
// FIXME: 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

Expand Down Expand Up @@ -56,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
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
warning: not reporting region error due to -Znll
--> $DIR/propagate-approximated-ref.rs:60:9
--> $DIR/propagate-approximated-ref.rs:57:9
|
60 | 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:58:47
--> $DIR/propagate-approximated-ref.rs:53:47
|
58 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
59 | | // Only works if 'x: 'y:
60 | | demand_y(x, y, x.get())
61 | | });
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: [closure@$DIR/propagate-approximated-ref.rs:58:47: 61:6<i16, for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r(7715))) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(7716))) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0(7717))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1(7718))) &'_#2r u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2(9542))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(7716))) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't3(9543))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1(7718))) u32>))>]
= note: defining type: [closure@$DIR/propagate-approximated-ref.rs:53:47: 58:6<i16, for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r(7715))) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(7716))) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0(7717))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1(7718))) &'_#2r u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2(9542))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(7716))) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't3(9543))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1(7718))) u32>))>]
= note: number of external vids: 3
= note: where '_#1r: '_#2r

error: free region `'_#1r` does not outlive free region `'_#2r`
--> $DIR/propagate-approximated-ref.rs:53:38
|
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| ^^^^^^^

note: No external requirements
--> $DIR/propagate-approximated-ref.rs:57:1
--> $DIR/propagate-approximated-ref.rs:52:1
|
57 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
58 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
59 | | // Only works if 'x: 'y:
60 | | demand_y(x, y, x.get())
61 | | });
62 | | }
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: for<'a, 'b> fn(std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(1:16), 'a(90))) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(1:17), 'b(92))) u32>) {supply}

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,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
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,50 @@
warning: not reporting region error due to -Znll
--> $DIR/propagate-approximated-to-static.rs:42:9
--> $DIR/propagate-approximated-to-static.rs:44:9
|
42 | demand_y(x, y, x.get())
44 | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
| ^^^^^^^^^^^^^^^^^^^^^^^

note: External requirements
--> $DIR/propagate-approximated-to-static.rs:40:47
|
40 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
| _______________________________________________^
41 | | // Only works if 'x: 'y:
42 | | demand_y(x, y, x.get())
43 | | });
41 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
42 | |
43 | | // Only works if 'x: 'y:
44 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
45 | | });
| |_____^
|
= note: defining type: [closure@$DIR/propagate-approximated-to-static.rs:40:47: 43:6<i16, for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r(7714))) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(7715))) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0(7716))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(7715))) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1(9540))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2(9541))) u32>))>]
= note: defining type: [closure@$DIR/propagate-approximated-to-static.rs:40:47: 45:6<i16, for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r(7714))) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(7715))) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0(7716))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(7715))) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1(9540))) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2(9541))) u32>))>]
= note: number of external vids: 2
= note: where '_#1r: '_#0r

error: free region `'_#1r` does not outlive free region `ReStatic`
--> $DIR/propagate-approximated-to-static.rs:40:47
|
40 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
| _______________________________________________^
41 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
42 | |
43 | | // Only works if 'x: 'y:
44 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
45 | | });
| |_____^

note: No external requirements
--> $DIR/propagate-approximated-to-static.rs:39:1
|
39 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
40 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
41 | | // Only works if 'x: 'y:
42 | | demand_y(x, y, x.get())
43 | | });
44 | | }
41 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
42 | |
... |
45 | | });
46 | | }
| |_^
|
= note: defining type: for<'a, 'b> fn(std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(1:16), 'a(90))) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(1:17), 'b(92))) u32>) {supply}

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -44,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
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
warning: not reporting region error due to -Znll
--> $DIR/propagate-approximated-val.rs:48:9
--> $DIR/propagate-approximated-val.rs:50:9
|
48 | 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:46:45
|
46 | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
| _____________________________________________^
47 | | // Only works if 'x: 'y:
48 | | demand_y(outlives1, outlives2, x.get())
49 | | });
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: [closure@$DIR/propagate-approximated-val.rs:46:45: 49:6<i16, for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r(9537))) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(9538))) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r(9537))) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(9538))) u32>))>]
= note: defining type: [closure@$DIR/propagate-approximated-val.rs:46:45: 51:6<i16, for<'r, 's> extern "rust-call" fn((std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r(9537))) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(9538))) &'_#2r u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r(9537))) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's(9538))) u32>))>]
= note: number of external vids: 3
= note: where '_#1r: '_#2r

error: free region `'_#1r` does not outlive free region `'_#2r`
--> $DIR/propagate-approximated-val.rs:46:37
|
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 | | // Only works if 'x: 'y:
48 | | demand_y(outlives1, outlives2, x.get())
49 | | });
50 | | }
47 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
48 | |
... |
51 | | });
52 | | }
| |_^
|
= note: defining type: for<'a, 'b> fn(std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(1:16), 'a(90))) u32>, std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(1:17), 'b(92))) u32>) {test}

error: aborting due to previous error

0 comments on commit 3eb4284

Please sign in to comment.