]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-fn-subtyping-return-static.rs
Rollup merge of #57232 - Zoxc:par-collector-misc, r=michaelwoerister
[rust.git] / src / test / ui / regions / regions-fn-subtyping-return-static.rs
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 // compile-pass
10
11 #![allow(dead_code)]
12 #![allow(unused_variables)]
13 #![allow(non_snake_case)]
14
15 struct S;
16
17 // Given 'cx, return 'cx
18 type F = for<'cx> fn(&'cx S) -> &'cx S;
19 fn want_F(f: F) { }
20
21 // Given anything, return 'static
22 type G = for<'cx> fn(&'cx S) -> &'static S;
23 fn want_G(f: G) { }
24
25 // Should meet both.
26 fn foo(x: &S) -> &'static S {
27     panic!()
28 }
29
30 // Should meet both.
31 fn bar<'a,'b>(x: &'a S) -> &'b S {
32     panic!()
33 }
34
35 // Meets F, but not G.
36 fn baz(x: &S) -> &S {
37     panic!()
38 }
39
40 fn supply_F() {
41     want_F(foo);
42
43     want_F(bar);
44
45     want_F(baz);
46 }
47
48 pub fn main() {
49 }