]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/mir_check_cast_reify.rs
fix merge conflicts
[rust.git] / src / test / ui / nll / mir_check_cast_reify.rs
1 // compile-flags: -Zborrowck=mir
2
3 #![allow(dead_code)]
4
5 // Test that we relate the type of the fn type to the type of the fn
6 // ptr when doing a `ReifyFnPointer` cast.
7 //
8 // This test is a bit tortured, let me explain:
9 //
10
11 // The `where 'a: 'a` clause here ensures that `'a` is early bound,
12 // which is needed below to ensure that this test hits the path we are
13 // concerned with.
14 fn foo<'a>(x: &'a u32) -> &'a u32
15 where
16     'a: 'a,
17 {
18     panic!()
19 }
20
21 fn bar<'a>(x: &'a u32) -> &'static u32 {
22     // Here, the type of `foo` is `typeof(foo::<'x>)` for some fresh variable `'x`.
23     // During NLL region analysis, this will get renumbered to `typeof(foo::<'?0>)`
24     // where `'?0` is a new region variable.
25     //
26     // (Note that if `'a` on `foo` were late-bound, the type would be
27     // `typeof(foo)`, which would interact differently with because
28     // the renumbering later.)
29     //
30     // This type is then coerced to a fn type `fn(&'?1 u32) -> &'?2
31     // u32`. Here, the `'?1` and `'?2` will have been created during
32     // the NLL region renumbering.
33     //
34     // The MIR type checker must therefore relate `'?0` to `'?1` and `'?2`
35     // as part of checking the `ReifyFnPointer`.
36     let f: fn(_) -> _ = foo;
37     f(x)
38     //~^ ERROR lifetime may not live long enough
39 }
40
41 fn main() {}