]> git.lizzy.rs Git - rust.git/blob - src/test/ui/rfc-1445-restrict-constants-in-patterns/issue-63479-match-fnptr.rs
Auto merge of #106143 - matthiaskrgr:rollup-3kpy1dc, r=matthiaskrgr
[rust.git] / src / test / ui / rfc-1445-restrict-constants-in-patterns / issue-63479-match-fnptr.rs
1 // run-pass
2
3 // The actual regression test from #63479. (Including this because my
4 // first draft at fn-ptr-is-structurally-matchable.rs failed to actually
5 // cover the case this hit; I've since expanded it accordingly, but the
6 // experience left me wary of leaving this regression test out.)
7
8 #![warn(pointer_structural_match)]
9
10 #[derive(Eq)]
11 struct A {
12   a: i64
13 }
14
15 impl PartialEq for A {
16     #[inline]
17     fn eq(&self, other: &Self) -> bool {
18         self.a.eq(&other.a)
19     }
20 }
21
22 type Fn = fn(&[A]);
23
24 fn my_fn(_args: &[A]) {
25   println!("hello world");
26 }
27
28 const TEST: Fn = my_fn;
29
30 struct B(Fn);
31
32 fn main() {
33   let s = B(my_fn);
34   match s {
35     B(TEST) => println!("matched"),
36      //~^ WARN pointers in patterns behave unpredictably
37     //~| WARN this was previously accepted by the compiler but is being phased out
38     _ => panic!("didn't match")
39   };
40 }