]>
Commit | Line | Data |
---|---|---|
abe05a73 | 1 | fn with_closure_expecting_fn_with_free_region<F>(_: F) |
f035d41b XL |
2 | where |
3 | F: for<'a> FnOnce(fn(&'a u32), &i32), | |
abe05a73 XL |
4 | { |
5 | } | |
6 | ||
7 | fn with_closure_expecting_fn_with_bound_region<F>(_: F) | |
f035d41b XL |
8 | where |
9 | F: FnOnce(fn(&u32), &i32), | |
abe05a73 XL |
10 | { |
11 | } | |
12 | ||
13 | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) { | |
14 | // Here, the type given for `'x` "obscures" a region from the | |
15 | // expected signature that is bound at closure level. | |
16 | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {}); | |
923072b8 FG |
17 | //~^ ERROR lifetime may not live long enough |
18 | //~| ERROR lifetime may not live long enough | |
abe05a73 XL |
19 | } |
20 | ||
21 | fn expect_free_supply_free_from_closure() { | |
22 | // A variant on the previous test. Here, the region `'a` will be | |
23 | // bound at the closure level, just as is expected, so no error | |
24 | // results. | |
25 | type Foo<'a> = fn(&'a u32); | |
26 | with_closure_expecting_fn_with_free_region(|_x: Foo<'_>, y| {}); | |
27 | } | |
28 | ||
29 | fn expect_free_supply_bound() { | |
30 | // Here, we are given a function whose region is bound at closure level, | |
31 | // but we expect one bound in the argument. Error results. | |
32 | with_closure_expecting_fn_with_free_region(|x: fn(&u32), y| {}); | |
f035d41b | 33 | //~^ ERROR mismatched types |
abe05a73 XL |
34 | } |
35 | ||
36 | fn expect_bound_supply_free_from_fn<'x>(x: &'x u32) { | |
37 | // Here, we are given a `fn(&u32)` but we expect a `fn(&'x | |
38 | // u32)`. In principle, this could be ok, but we demand equality. | |
39 | with_closure_expecting_fn_with_bound_region(|x: fn(&'x u32), y| {}); | |
f035d41b | 40 | //~^ ERROR mismatched types |
abe05a73 XL |
41 | } |
42 | ||
43 | fn expect_bound_supply_free_from_closure() { | |
44 | // A variant on the previous test. Here, the region `'a` will be | |
45 | // bound at the closure level, but we expect something bound at | |
46 | // the argument level. | |
47 | type Foo<'a> = fn(&'a u32); | |
0731742a | 48 | with_closure_expecting_fn_with_bound_region(|x: Foo<'_>, y| { |
f035d41b | 49 | //~^ ERROR mismatched types |
0731742a | 50 | }); |
abe05a73 XL |
51 | } |
52 | ||
53 | fn expect_bound_supply_bound<'x>(x: &'x u32) { | |
54 | // No error in this case. The supplied type supplies the bound | |
55 | // regions, and hence we are able to figure out the type of `y` | |
56 | // from the expected type | |
f035d41b | 57 | with_closure_expecting_fn_with_bound_region(|x: for<'z> fn(&'z u32), y| {}); |
abe05a73 XL |
58 | } |
59 | ||
f035d41b | 60 | fn main() {} |