1 // Copyright 2017 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 // compile-flags: -Zborrowck=mir
15 // Test that we relate the type of the fn type to the type of the fn
16 // ptr when doing a `ReifyFnPointer` cast.
18 // This test is a bit tortured, let me explain:
21 // The `where 'a: 'a` clause here ensures that `'a` is early bound,
22 // which is needed below to ensure that this test hits the path we are
24 fn foo<'a>(x: &'a u32) -> &'a u32
31 fn bar<'a>(x: &'a u32) -> &'static u32 {
32 // Here, the type of `foo` is `typeof(foo::<'x>)` for some fresh variable `'x`.
33 // During NLL region analysis, this will get renumbered to `typeof(foo::<'?0>)`
34 // where `'?0` is a new region variable.
36 // (Note that if `'a` on `foo` were late-bound, the type would be
37 // `typeof(foo)`, which would interact differently with because
38 // the renumbering later.)
40 // This type is then coerced to a fn type `fn(&'?1 u32) -> &'?2
41 // u32`. Here, the `'?1` and `'?2` will have been created during
42 // the NLL region renumbering.
44 // The MIR type checker must therefore relate `'?0` to `'?1` and `'?2`
45 // as part of checking the `ReifyFnPointer`.
46 let f: fn(_) -> _ = foo;
48 //~^ ERROR unsatisfied lifetime constraints