]>
git.proxmox.com Git - rustc.git/blob - 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.
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.
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.
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.
20 #![allow(unused_variables)]
24 // Given 'cx, return 'cx
25 type F
= for<'cx
> fn(&'cx S
) -> &'cx S
;
28 // Given anything, return 'static
29 type G
= for<'cx
> fn(&'cx S
) -> &'
static S
;
33 fn foo(x
: &S
) -> &'
static S
{
38 fn bar
<'a
,'b
>(x
: &'a S
) -> &'b S
{
42 // Meets F, but not G.
50 // FIXME(#33684) -- this should be a subtype, but current alg. rejects it incorrectly
51 want_F(bar
); //~ ERROR E0308
60 //~^ ERROR mismatched types
61 //~| expected type `for<'cx> fn(&'cx S) -> &'static S`
62 //~| found type `for<'r> fn(&'r S) -> &'r S {baz}`
63 //~| expected concrete lifetime, found bound lifetime parameter 'cx