]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2012 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | // In this fn, the type `F` is a function that takes a reference to a | |
12 | // struct and returns another reference with the same lifetime. | |
13 | // | |
14 | // Meanwhile, the bare fn `foo` takes a reference to a struct with | |
15 | // *ANY* lifetime and returns a reference with the 'static lifetime. | |
16 | // This can safely be considered to be an instance of `F` because all | |
17 | // lifetimes are sublifetimes of 'static. | |
18 | ||
19 | #![allow(dead_code)] | |
20 | #![allow(unused_variables)] | |
21 | ||
22 | struct S; | |
23 | ||
24 | // Given 'cx, return 'cx | |
25 | type F = for<'cx> fn(&'cx S) -> &'cx S; | |
26 | fn want_F(f: F) { } | |
27 | ||
28 | // Given anything, return 'static | |
29 | type G = for<'cx> fn(&'cx S) -> &'static S; | |
30 | fn want_G(f: G) { } | |
31 | ||
32 | // Should meet both. | |
33 | fn foo(x: &S) -> &'static S { | |
34 | panic!() | |
35 | } | |
36 | ||
37 | // Should meet both. | |
38 | fn bar<'a,'b>(x: &'a S) -> &'b S { | |
39 | panic!() | |
40 | } | |
41 | ||
42 | // Meets F, but not G. | |
43 | fn baz(x: &S) -> &S { | |
44 | panic!() | |
45 | } | |
46 | ||
47 | fn supply_F() { | |
48 | want_F(foo); | |
8bb4bdeb XL |
49 | |
50 | // FIXME(#33684) -- this should be a subtype, but current alg. rejects it incorrectly | |
51 | want_F(bar); //~ ERROR E0308 | |
52 | ||
1a4d82fc JJ |
53 | want_F(baz); |
54 | } | |
55 | ||
56 | fn supply_G() { | |
57 | want_G(foo); | |
58 | want_G(bar); | |
85aaf69f SL |
59 | want_G(baz); |
60 | //~^ ERROR mismatched types | |
abe05a73 XL |
61 | //~| expected type `for<'cx> fn(&'cx S) -> &'static S` |
62 | //~| found type `for<'r> fn(&'r S) -> &'r S {baz}` | |
a7813a04 | 63 | //~| expected concrete lifetime, found bound lifetime parameter 'cx |
1a4d82fc JJ |
64 | } |
65 | ||
66 | pub fn main() { | |
67 | } |