]> git.proxmox.com Git - rustc.git/blob - src/test/ui/hrtb/issue-46989.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / src / test / ui / hrtb / issue-46989.rs
1 // Regression test for #46989:
2 //
3 // In the move to universes, this test started passing.
4 // It is not necessarily WRONG to do so, but it was a bit
5 // surprising. The reason that it passed is that when we were
6 // asked to prove that
7 //
8 // for<'a> fn(&'a i32): Foo
9 //
10 // we were able to use the impl below to prove
11 //
12 // fn(&'empty i32): Foo
13 //
14 // and then we were able to prove that
15 //
16 // fn(&'empty i32) = for<'a> fn(&'a i32)
17 //
18 // This last fact is somewhat surprising, but essentially "falls out"
19 // from handling variance correctly. In particular, consider the subtyping
20 // relations. First:
21 //
22 // fn(&'empty i32) <: for<'a> fn(&'a i32)
23 //
24 // This holds because -- intuitively -- a fn that takes a reference but doesn't use
25 // it can be given a reference with any lifetime. Similarly, the opposite direction:
26 //
27 // for<'a> fn(&'a i32) <: fn(&'empty i32)
28 //
29 // holds because 'a can be instantiated to 'empty.
30
31 trait Foo {}
32
33 impl<A> Foo for fn(A) {}
34
35 fn assert_foo<T: Foo>() {}
36
37 fn main() {
38 assert_foo::<fn(&i32)>();
39 //~^ ERROR implementation of `Foo` is not general enough
40 }