]> git.proxmox.com Git - rustc.git/blob - src/test/ui/regions-fn-subtyping-return-static-fail.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / src / test / ui / regions-fn-subtyping-return-static-fail.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 #![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;
16 fn want_F(f: F) {}
17
18 // Given anything, return 'static
19 type G = for<'cx> fn(&'cx S) -> &'static S;
20 fn want_G(f: G) {}
21
22 // Should meet both.
23 fn foo(x: &S) -> &'static S {
24 panic!()
25 }
26
27 // Should meet both.
28 fn bar<'a, 'b>(x: &'a S) -> &'b S {
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);
39
40 want_F(bar);
41
42 want_F(baz);
43 }
44
45 fn supply_G() {
46 want_G(foo);
47 want_G(bar);
48 want_G(baz); //~ ERROR mismatched types
49 }
50
51 pub fn main() {}