]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/regions-fn-subtyping-return-static.rs
Unignore u128 test for stage 0,1
[rust.git] / src / test / compile-fail / regions-fn-subtyping-return-static.rs
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);
49     want_F(bar);
50     want_F(baz);
51 }
52
53 fn supply_G() {
54     want_G(foo);
55     want_G(bar);
56     want_G(baz);
57     //~^ ERROR mismatched types
58     //~| expected type `fn(&'cx S) -> &'static S`
59     //~| found type `fn(&S) -> &S {baz}`
60     //~| expected concrete lifetime, found bound lifetime parameter 'cx
61 }
62
63 pub fn main() {
64 }