]>
Commit | Line | Data |
---|---|---|
ff7c6d11 XL |
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. | |
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 | ||
83c7162d | 11 | // compile-flags: -Zborrowck=mir |
ff7c6d11 XL |
12 | |
13 | #![allow(dead_code)] | |
14 | ||
15 | // Test that we relate the type of the fn type to the type of the fn | |
16 | // ptr when doing a `ReifyFnPointer` cast. | |
17 | // | |
18 | // This test is a bit tortured, let me explain: | |
19 | // | |
20 | ||
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 | |
23 | // concerned with. | |
24 | fn foo<'a>(x: &'a u32) -> &'a u32 | |
25 | where | |
26 | 'a: 'a, | |
27 | { | |
28 | panic!() | |
29 | } | |
30 | ||
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. | |
35 | // | |
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.) | |
39 | // | |
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. | |
43 | // | |
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; | |
ff7c6d11 | 47 | f(x) |
0bf4aa26 | 48 | //~^ ERROR unsatisfied lifetime constraints |
ff7c6d11 XL |
49 | } |
50 | ||
51 | fn main() {} |