Skip to content

Commit 2921fba

Browse files
committed
flesh out closure-substs test
1 parent 0afccbb commit 2921fba

File tree

2 files changed

+66
-8
lines changed

2 files changed

+66
-8
lines changed

src/test/ui/nll/user-annotations/closure-substs.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,30 @@
1313
// Test that we enforce user-provided type annotations on closures.
1414

1515
fn foo<'a>() {
16+
// Here `x` is free in the closure sig:
1617
|x: &'a i32| -> &'static i32 {
17-
return x; //~ ERROR
18+
return x; //~ ERROR unsatisfied lifetime constraints
19+
};
20+
}
21+
22+
fn foo1() {
23+
// Here `x` is bound in the closure sig:
24+
|x: &i32| -> &'static i32 {
25+
return x; //~ ERROR unsatisfied lifetime constraints
26+
//~^ ERROR unsatisfied lifetime constraints
27+
//~| ERROR unsatisfied lifetime constraints
1828
};
1929
}
2030

2131
fn bar<'a>() {
32+
// Here `x` is free in the closure sig:
33+
|x: &'a i32, b: fn(&'static i32)| {
34+
b(x); //~ ERROR unsatisfied lifetime constraints
35+
};
36+
}
37+
38+
fn bar1() {
39+
// Here `x` is bound in the closure sig:
2240
|x: &i32, b: fn(&'static i32)| {
2341
b(x); //~ ERROR
2442
//~^ ERROR borrowed data escapes outside of closure
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,62 @@
11
error: unsatisfied lifetime constraints
2-
--> $DIR/closure-substs.rs:17:16
2+
--> $DIR/closure-substs.rs:18:16
33
|
44
LL | fn foo<'a>() {
55
| -- lifetime `'a` defined here
6-
LL | |x: &'a i32| -> &'static i32 {
7-
LL | return x; //~ ERROR
6+
...
7+
LL | return x; //~ ERROR unsatisfied lifetime constraints
88
| ^ returning this value requires that `'a` must outlive `'static`
99

10+
error: unsatisfied lifetime constraints
11+
--> $DIR/closure-substs.rs:25:16
12+
|
13+
LL | |x: &i32| -> &'static i32 {
14+
| - let's call the lifetime of this reference `'1`
15+
LL | return x; //~ ERROR unsatisfied lifetime constraints
16+
| ^ returning this value requires that `'1` must outlive `'static`
17+
18+
error: unsatisfied lifetime constraints
19+
--> $DIR/closure-substs.rs:25:16
20+
|
21+
LL | |x: &i32| -> &'static i32 {
22+
| - - return type of closure is &'2 i32
23+
| |
24+
| let's call the lifetime of this reference `'1`
25+
LL | return x; //~ ERROR unsatisfied lifetime constraints
26+
| ^ returning this value requires that `'1` must outlive `'2`
27+
28+
error: unsatisfied lifetime constraints
29+
--> $DIR/closure-substs.rs:25:16
30+
|
31+
LL | |x: &i32| -> &'static i32 {
32+
| -------------------------
33+
| | |
34+
| | let's call the lifetime of this reference `'1`
35+
| lifetime `'2` represents this closure's body
36+
LL | return x; //~ ERROR unsatisfied lifetime constraints
37+
| ^ closure was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
38+
|
39+
= note: closure implements `Fn`, so references to captured variables can't escape the closure
40+
41+
error: unsatisfied lifetime constraints
42+
--> $DIR/closure-substs.rs:34:9
43+
|
44+
LL | fn bar<'a>() {
45+
| -- lifetime `'a` defined here
46+
...
47+
LL | b(x); //~ ERROR unsatisfied lifetime constraints
48+
| ^^^^ argument requires that `'a` must outlive `'static`
49+
1050
error: borrowed data escapes outside of closure
11-
--> $DIR/closure-substs.rs:23:9
51+
--> $DIR/closure-substs.rs:41:9
1252
|
1353
LL | |x: &i32, b: fn(&'static i32)| {
1454
| - `x` is a reference that is only valid in the closure body
1555
LL | b(x); //~ ERROR
1656
| ^^^^ `x` escapes the closure body here
1757

1858
error: borrowed data escapes outside of closure
19-
--> $DIR/closure-substs.rs:23:9
59+
--> $DIR/closure-substs.rs:41:9
2060
|
2161
LL | |x: &i32, b: fn(&'static i32)| {
2262
| - - `b` is declared here, outside of the closure body
@@ -26,7 +66,7 @@ LL | b(x); //~ ERROR
2666
| ^^^^ `x` escapes the closure body here
2767

2868
error: unsatisfied lifetime constraints
29-
--> $DIR/closure-substs.rs:23:9
69+
--> $DIR/closure-substs.rs:41:9
3070
|
3171
LL | |x: &i32, b: fn(&'static i32)| {
3272
| ------------------------------
@@ -38,5 +78,5 @@ LL | b(x); //~ ERROR
3878
|
3979
= note: closure implements `Fn`, so references to captured variables can't escape the closure
4080

41-
error: aborting due to 4 previous errors
81+
error: aborting due to 8 previous errors
4282

0 commit comments

Comments
 (0)