]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // In this fn, the type `F` is a function that takes a reference to a |
2 | // struct and returns another reference with the same lifetime. | |
3 | // | |
4 | // Meanwhile, the bare fn `foo` takes a reference to a struct with | |
5 | // *ANY* lifetime and returns a reference with the 'static lifetime. | |
6 | // This can safely be considered to be an instance of `F` because all | |
7 | // lifetimes are sublifetimes of 'static. | |
8 | ||
9 | #![allow(dead_code)] | |
10 | #![allow(unused_variables)] | |
11 | ||
12 | struct S; | |
13 | ||
14 | // Given 'cx, return 'cx | |
15 | type F = for<'cx> fn(&'cx S) -> &'cx S; | |
f035d41b | 16 | fn want_F(f: F) {} |
1a4d82fc JJ |
17 | |
18 | // Given anything, return 'static | |
19 | type G = for<'cx> fn(&'cx S) -> &'static S; | |
f035d41b | 20 | fn want_G(f: G) {} |
1a4d82fc JJ |
21 | |
22 | // Should meet both. | |
23 | fn foo(x: &S) -> &'static S { | |
24 | panic!() | |
25 | } | |
26 | ||
27 | // Should meet both. | |
f035d41b | 28 | fn bar<'a, 'b>(x: &'a S) -> &'b S { |
1a4d82fc JJ |
29 | panic!() |
30 | } | |
31 | ||
32 | // Meets F, but not G. | |
33 | fn baz(x: &S) -> &S { | |
34 | panic!() | |
35 | } | |
36 | ||
37 | fn supply_F() { | |
38 | want_F(foo); | |
8bb4bdeb | 39 | |
f035d41b | 40 | want_F(bar); |
8bb4bdeb | 41 | |
1a4d82fc JJ |
42 | want_F(baz); |
43 | } | |
44 | ||
45 | fn supply_G() { | |
46 | want_G(foo); | |
47 | want_G(bar); | |
0731742a | 48 | want_G(baz); //~ ERROR mismatched types |
1a4d82fc JJ |
49 | } |
50 | ||
f035d41b | 51 | pub fn main() {} |