3 // This file checks that fn ptrs are considered structurally matchable.
4 // See also rust-lang/rust#63479.
9 // A type which is not structurally matchable:
13 #[derive(PartialEq, Eq)]
19 fn not_sm_to(_: NotSM) {}
20 fn to_sm() -> SM { SM }
21 fn to_not_sm() -> NotSM { NotSM }
23 // To recreate the scenario of interest in #63479, we need to add
24 // a ref-level-of-indirection so that we descend into the type.
27 fn r_not_sm_to(_: &NotSM) {}
28 fn r_to_r_sm(_: &()) -> &SM { &SM }
29 fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
31 #[derive(PartialEq, Eq)]
34 // In the code below, we put the match input into a local so that
35 // we can assign it an explicit type that is an fn ptr instead of
36 // a singleton type of the fn itself that the type inference would
39 // Check that fn() is structural-match
40 const CFN1: Wrap<fn()> = Wrap(trivial);
41 let input: Wrap<fn()> = Wrap(trivial);
43 Wrap(CFN1) => count += 1,
47 // Check that fn(T) is structural-match when T is too.
48 const CFN2: Wrap<fn(SM)> = Wrap(sm_to);
49 let input: Wrap<fn(SM)> = Wrap(sm_to);
51 Wrap(CFN2) => count += 1,
55 // Check that fn() -> T is structural-match when T is too.
56 const CFN3: Wrap<fn() -> SM> = Wrap(to_sm);
57 let input: Wrap<fn() -> SM> = Wrap(to_sm);
59 Wrap(CFN3) => count += 1,
63 // Check that fn(T) is structural-match even if T is not.
64 const CFN4: Wrap<fn(NotSM)> = Wrap(not_sm_to);
65 let input: Wrap<fn(NotSM)> = Wrap(not_sm_to);
67 Wrap(CFN4) => count += 1,
71 // Check that fn() -> T is structural-match even if T is not.
72 const CFN5: Wrap<fn() -> NotSM> = Wrap(to_not_sm);
73 let input: Wrap<fn() -> NotSM> = Wrap(to_not_sm);
75 Wrap(CFN5) => count += 1,
79 // Check that fn(&T) is structural-match when T is too.
80 const CFN6: Wrap<fn(&SM)> = Wrap(r_sm_to);
81 let input: Wrap<fn(&SM)> = Wrap(r_sm_to);
83 Wrap(CFN6) => count += 1,
87 // Check that fn() -> &T is structural-match when T is too.
88 const CFN7: Wrap<fn(&()) -> &SM> = Wrap(r_to_r_sm);
89 let input: Wrap<fn(&()) -> &SM> = Wrap(r_to_r_sm);
91 Wrap(CFN7) => count += 1,
95 // Check that fn(T) is structural-match even if T is not.
96 const CFN8: Wrap<fn(&NotSM)> = Wrap(r_not_sm_to);
97 let input: Wrap<fn(&NotSM)> = Wrap(r_not_sm_to);
99 Wrap(CFN8) => count += 1,
103 // Check that fn() -> T is structural-match even if T is not.
104 const CFN9: Wrap<fn(&()) -> &NotSM> = Wrap(r_to_r_not_sm);
105 let input: Wrap<fn(&()) -> &NotSM> = Wrap(r_to_r_not_sm);
107 Wrap(CFN9) => count += 1,
111 // Check that a type which has fn ptrs is structural-match.
112 #[derive(PartialEq, Eq)]
120 const CFOO: Foo = Foo {
127 let input = Foo { alpha: not_sm_to, beta: to_not_sm, gamma: sm_to, delta: to_sm };
133 // Final count must be 10 now if all
134 assert_eq!(count, 10);