]> git.proxmox.com Git - rustc.git/blame - src/test/ui/regions/regions-fn-subtyping-return-static-fail.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / regions / regions-fn-subtyping-return-static-fail.rs
CommitLineData
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
12struct S;
13
14// Given 'cx, return 'cx
15type F = for<'cx> fn(&'cx S) -> &'cx S;
f035d41b 16fn want_F(f: F) {}
1a4d82fc
JJ
17
18// Given anything, return 'static
19type G = for<'cx> fn(&'cx S) -> &'static S;
f035d41b 20fn want_G(f: G) {}
1a4d82fc
JJ
21
22// Should meet both.
23fn foo(x: &S) -> &'static S {
24 panic!()
25}
26
27// Should meet both.
f035d41b 28fn bar<'a, 'b>(x: &'a S) -> &'b S {
1a4d82fc
JJ
29 panic!()
30}
31
32// Meets F, but not G.
33fn baz(x: &S) -> &S {
34 panic!()
35}
36
37fn supply_F() {
38 want_F(foo);
8bb4bdeb 39
f035d41b 40 want_F(bar);
8bb4bdeb 41
1a4d82fc
JJ
42 want_F(baz);
43}
44
45fn supply_G() {
46 want_G(foo);
47 want_G(bar);
0731742a 48 want_G(baz); //~ ERROR mismatched types
1a4d82fc
JJ
49}
50
f035d41b 51pub fn main() {}