Skip to content

Commit a30e225

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 decbbb3 commit a30e225

12 files changed

+142
-79
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ 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;
31+
//~^ ERROR `x` does not live long enough
3132
let w = Foo { t: p };
3233

3334
let v = [w; 22];
@@ -36,4 +37,3 @@ fn main() {
3637
x += 1;
3738
//~^ ERROR cannot assign to `x` because it is borrowed [E0506]
3839
}
39-
//~^ ERROR borrowed value does not live long enough [E0597]

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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@
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
31-
// must-compile-successfully
3226

3327
#![feature(rustc_attrs)]
3428

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

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:61:9
2+
--> $DIR/propagate-approximated-ref.rs:57:9
33
|
4-
61 | 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:59:47
8+
--> $DIR/propagate-approximated-ref.rs:53:47
99
|
10-
59 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
10+
53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
1111
| _______________________________________________^
12-
60 | | // Only works if 'x: 'y:
13-
61 | | demand_y(x, y, x.get())
14-
62 | | });
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:58:1
33+
--> $DIR/propagate-approximated-ref.rs:52:1
2634
|
27-
58 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
28-
59 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
29-
60 | | // Only works if 'x: 'y:
30-
61 | | demand_y(x, y, x.get())
31-
62 | | });
32-
63 | | }
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
@@ -39,12 +39,10 @@ fn case1() {
3939
fn case2() {
4040
let a = 0;
4141
let cell = Cell::new(&a);
42+
//~^ ERROR `a` does not live long enough
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: 19 additions & 8 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 [
@@ -63,13 +63,24 @@ note: No external requirements
6363
39 | / fn case2() {
6464
40 | | let a = 0;
6565
41 | | let cell = Cell::new(&a);
66-
42 | |
66+
42 | | //~^ ERROR `a` does not live long enough
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]: `a` does not live long enough
75+
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:41:26
76+
|
77+
41 | let cell = Cell::new(&a);
78+
| ^^ does not live long enough
79+
...
80+
49 | }
81+
| - borrowed value only lives until here
82+
|
83+
= note: borrowed value must be valid for lifetime '_#1r...
84+
85+
error: aborting due to 2 previous errors
7586

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// these errors are not (yet) reported.
1818

1919
// compile-flags:-Znll -Zborrowck=mir -Zverbose
20-
// must-compile-successfully
2120

2221
#![feature(rustc_attrs)]
2322

@@ -44,8 +43,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
4443
#[rustc_regions]
4544
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4645
establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
46+
//~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
47+
4748
// Only works if 'x: 'y:
48-
demand_y(x, y, x.get())
49+
demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll
4950
});
5051
}
5152

Lines changed: 31 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-shorter-to-static-no-bound.rs:48:9
2+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:49:9
33
|
4-
48 | 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
8-
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:46:47
8+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
99
|
10-
46 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
10+
45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
1111
| _______________________________________________^
12-
47 | | // Only works if 'x: 'y:
13-
48 | | demand_y(x, y, x.get())
14-
49 | | });
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
25-
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:1
39+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1
2640
|
27-
45 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
28-
46 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
29-
47 | | // Only works if 'x: 'y:
30-
48 | | demand_y(x, y, x.get())
31-
49 | | });
32-
50 | | }
41+
44 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
42+
45 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
// these errors are not (yet) reported.
1919

2020
// compile-flags:-Znll -Zborrowck=mir -Zverbose
21-
// must-compile-successfully
2221

2322
#![feature(rustc_attrs)]
2423

@@ -47,8 +46,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
4746
#[rustc_regions]
4847
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
4948
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
49+
//~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
5050
// Only works if 'x: 'y:
5151
demand_y(x, y, x.get())
52+
//~^ WARNING not reporting region error due to -Znll
5253
});
5354
}
5455

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ warning: not reporting region error due to -Znll
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66

77
note: External requirements
8-
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:49:47
8+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
99
|
10-
49 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
10+
48 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
1111
| _______________________________________________^
12+
49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic`
1213
50 | | // Only works if 'x: 'y:
1314
51 | | demand_y(x, y, x.get())
14-
52 | | });
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

24-
note: No external requirements
25-
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:1
26+
error: free region `'_#1r` does not outlive free region `ReStatic`
27+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
2628
|
27-
48 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
28-
49 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
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`
2932
50 | | // Only works if 'x: 'y:
3033
51 | | demand_y(x, y, x.get())
31-
52 | | });
32-
53 | | }
34+
52 | | //~^ WARNING not reporting region error due to -Znll
35+
53 | | });
36+
| |_____^
37+
38+
note: No external requirements
39+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1
40+
|
41+
47 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
42+
48 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
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)