]> git.proxmox.com Git - rustc.git/blame - src/test/ui/hrtb/issue-46989.rs
New upstream version 1.49.0+dfsg1
[rustc.git] / src / test / ui / hrtb / issue-46989.rs
CommitLineData
0731742a
XL
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
72b1a166 31trait Foo {}
0731742a 32
72b1a166 33impl<A> Foo for fn(A) {}
0731742a
XL
34
35fn assert_foo<T: Foo>() {}
36
37fn main() {
38 assert_foo::<fn(&i32)>();
72b1a166 39 //~^ ERROR implementation of `Foo` is not general enough
0731742a 40}