Skip to content

Commit 7269695

Browse files
committed
fix closure tests now that MIR typeck works properly
These tests had FIXMEs for errors that were not previously being reported.
1 parent f9a6ab8 commit 7269695

12 files changed

+137
-66
lines changed

src/test/compile-fail/nll/where_clauses_in_repeat_rvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn main() {
2727
let mut x = 22;
2828

2929
{
30-
let p = &x; //~ ERROR borrowed value does not live long enough
30+
let p = &x;
3131
let w = Foo { t: p };
3232

3333
let v = [w; 22];

src/test/compile-fail/regions-static-bound.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
2424
fn error(u: &(), v: &()) {
2525
static_id(&u); //[ll]~ ERROR cannot infer an appropriate lifetime
2626
//[nll]~^ WARNING not reporting region error due to -Znll
27+
//[nll]~| ERROR free region `'_#1r` does not outlive free region `'static`
2728
static_id_indirect(&v); //[ll]~ ERROR cannot infer an appropriate lifetime
2829
//[nll]~^ WARNING not reporting region error due to -Znll
29-
30-
// FIXME(#45827) -- MIR type checker shortcomings mean we don't
31-
// see these errors (yet) in nll mode.
30+
//[nll]~| ERROR free region `'_#2r` does not outlive free region `'static`
3231
}
3332

3433
fn main() {}

src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@
2121
//
2222
// Note: the use of `Cell` here is to introduce invariance. One less
2323
// variable.
24-
//
25-
// FIXME(#45827): The `supply` function *ought* to generate an error, but it
26-
// currently does not. This is I believe a shortcoming of the MIR type
27-
// checker: the closure inference is expressing the correct
28-
// requirement, as you can see from the `#[rustc_regions]` output.
2924

3025
// compile-flags:-Znll -Zborrowck=mir -Zverbose
3126

@@ -56,8 +51,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
5651
#[rustc_regions]
5752
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
5853
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
54+
//~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
55+
5956
// Only works if 'x: 'y:
60-
demand_y(x, y, x.get())
57+
demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
6158
});
6259
}
6360

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
warning: not reporting region error due to -Znll
2-
--> $DIR/propagate-approximated-ref.rs:60:9
2+
--> $DIR/propagate-approximated-ref.rs:57:9
33
|
4-
60 | demand_y(x, y, x.get())
4+
57 | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66

77
note: External requirements
8-
--> $DIR/propagate-approximated-ref.rs:58:47
8+
--> $DIR/propagate-approximated-ref.rs:53:47
99
|
10-
58 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
10+
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
1111
| _______________________________________________^
12-
59 | | // Only works if 'x: 'y:
13-
60 | | demand_y(x, y, x.get())
14-
61 | | });
12+
54 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
13+
55 | |
14+
56 | | // Only works if 'x: 'y:
15+
57 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
16+
58 | | });
1517
| |_____^
1618
|
1719
= 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
2123
= note: number of external vids: 3
2224
= note: where '_#1r: '_#2r
2325

26+
error: free region `'_#1r` does not outlive free region `'_#2r`
27+
--> $DIR/propagate-approximated-ref.rs:53:38
28+
|
29+
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
30+
| ^^^^^^^
31+
2432
note: No external requirements
25-
--> $DIR/propagate-approximated-ref.rs:57:1
33+
--> $DIR/propagate-approximated-ref.rs:52:1
2634
|
27-
57 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
28-
58 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
29-
59 | | // Only works if 'x: 'y:
30-
60 | | demand_y(x, y, x.get())
31-
61 | | });
32-
62 | | }
35+
52 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
36+
53 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
37+
54 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r`
38+
55 | |
39+
... |
40+
58 | | });
41+
59 | | }
3342
| |_^
3443
|
3544
= note: defining type: DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]) with substs []
3645

46+
error: aborting due to previous error
47+

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ fn case1() {
3737

3838
#[rustc_regions]
3939
fn case2() {
40+
//~^ ERROR borrowed value does not live long enough
4041
let a = 0;
4142
let cell = Cell::new(&a);
4243

4344
// As you can see in the stderr output, this closure propoagates a
4445
// requirement that `'a: 'static'.
45-
//
46-
// FIXME(#45827) However, because of shortcomings in the MIR type
47-
// checker, this does not result in errors later on (yet).
4846
foo(cell, |cell_a, cell_x| {
4947
cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
5048
})

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ note: No external requirements
4242
= note: defining type: DefId(0/0:5 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]) with substs []
4343

4444
note: External requirements
45-
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:48:15
45+
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:46:15
4646
|
47-
48 | foo(cell, |cell_a, cell_x| {
47+
46 | foo(cell, |cell_a, cell_x| {
4848
| _______________^
49-
49 | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
50-
50 | | })
49+
47 | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
50+
48 | | })
5151
| |_____^
5252
|
5353
= note: defining type: DefId(0/1:13 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [
@@ -61,15 +61,30 @@ note: No external requirements
6161
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:39:1
6262
|
6363
39 | / fn case2() {
64-
40 | | let a = 0;
65-
41 | | let cell = Cell::new(&a);
66-
42 | |
64+
40 | | //~^ ERROR borrowed value does not live long enough
65+
41 | | let a = 0;
66+
42 | | let cell = Cell::new(&a);
6767
... |
68-
50 | | })
69-
51 | | }
68+
48 | | })
69+
49 | | }
7070
| |_^
7171
|
7272
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]) with substs []
7373

74-
error: aborting due to previous error
74+
error[E0597]: borrowed value does not live long enough
75+
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:39:1
76+
|
77+
39 | / fn case2() {
78+
40 | | //~^ ERROR borrowed value does not live long enough
79+
41 | | let a = 0;
80+
| | - temporary value created here
81+
42 | | let cell = Cell::new(&a);
82+
... |
83+
48 | | })
84+
49 | | }
85+
| |_^ temporary value dropped here while still borrowed
86+
|
87+
= note: consider using a `let` binding to increase its lifetime
88+
89+
error: aborting due to 2 previous errors
7590

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
4343
#[rustc_regions]
4444
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4545
establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
46+
//~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
47+
4648
// Only works if 'x: 'y:
47-
demand_y(x, y, x.get())
49+
demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
4850
});
4951
}
5052

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
warning: not reporting region error due to -Znll
2-
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:47:9
2+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:49:9
33
|
4-
47 | demand_y(x, y, x.get())
4+
49 | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66

77
note: External requirements
88
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
99
|
1010
45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
1111
| _______________________________________________^
12-
46 | | // Only works if 'x: 'y:
13-
47 | | demand_y(x, y, x.get())
14-
48 | | });
12+
46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
13+
47 | |
14+
48 | | // Only works if 'x: 'y:
15+
49 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
16+
50 | | });
1517
| |_____^
1618
|
1719
= 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
2123
= note: number of external vids: 2
2224
= note: where '_#1r: '_#0r
2325

26+
error: free region `'_#1r` does not outlive free region `ReStatic`
27+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
28+
|
29+
45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
30+
| _______________________________________________^
31+
46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
32+
47 | |
33+
48 | | // Only works if 'x: 'y:
34+
49 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
35+
50 | | });
36+
| |_____^
37+
2438
note: No external requirements
2539
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1
2640
|
2741
44 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2842
45 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
29-
46 | | // Only works if 'x: 'y:
30-
47 | | demand_y(x, y, x.get())
31-
48 | | });
32-
49 | | }
43+
46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
44+
47 | |
45+
... |
46+
50 | | });
47+
51 | | }
3348
| |_^
3449
|
3550
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []
3651

52+
error: aborting due to previous error
53+

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
4646
#[rustc_regions]
4747
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4848
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
49+
//~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
4950
// Only works if 'x: 'y:
5051
demand_y(x, y, x.get())
52+
//~^ WARNING not reporting region error due to -Znll
5153
});
5254
}
5355

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
warning: not reporting region error due to -Znll
2-
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:50:9
2+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:51:9
33
|
4-
50 | demand_y(x, y, x.get())
4+
51 | demand_y(x, y, x.get())
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66

77
note: External requirements
88
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
99
|
1010
48 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
1111
| _______________________________________________^
12-
49 | | // Only works if 'x: 'y:
13-
50 | | demand_y(x, y, x.get())
14-
51 | | });
12+
49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
13+
50 | | // Only works if 'x: 'y:
14+
51 | | demand_y(x, y, x.get())
15+
52 | | //~^ WARNING not reporting region error due to -Znll
16+
53 | | });
1517
| |_____^
1618
|
1719
= 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
2123
= note: number of external vids: 3
2224
= note: where '_#1r: '_#0r
2325

26+
error: free region `'_#1r` does not outlive free region `ReStatic`
27+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
28+
|
29+
48 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
30+
| _______________________________________________^
31+
49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
32+
50 | | // Only works if 'x: 'y:
33+
51 | | demand_y(x, y, x.get())
34+
52 | | //~^ WARNING not reporting region error due to -Znll
35+
53 | | });
36+
| |_____^
37+
2438
note: No external requirements
2539
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1
2640
|
2741
47 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
2842
48 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
29-
49 | | // Only works if 'x: 'y:
30-
50 | | demand_y(x, y, x.get())
31-
51 | | });
32-
52 | | }
43+
49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
44+
50 | | // Only works if 'x: 'y:
45+
... |
46+
53 | | });
47+
54 | | }
3348
| |_^
3449
|
3550
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []
3651

52+
error: aborting due to previous error
53+

0 commit comments

Comments
 (0)