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