]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | // RFC 1445 introduced `#[structural_match]`; this attribute must |
2 | // appear on the `struct`/`enum` definition for any `const` used in a | |
3 | // pattern. | |
4 | // | |
5 | // This is our (forever-unstable) way to mark a datatype as having a | |
6 | // `PartialEq` implementation that is equivalent to recursion over its | |
7 | // substructure. This avoids (at least in the short term) any need to | |
8 | // resolve the question of what semantics is used for such matching. | |
9 | // (See RFC 1445 for more details and discussion.) | |
10 | ||
11 | // Issue 62307 pointed out a case where the checking for | |
12 | // `#[structural_match]` was too shallow. | |
13 | #![warn(indirect_structural_match)] | |
14 | // run-pass | |
15 | ||
16 | #[derive(Debug)] | |
17 | struct B(i32); | |
18 | ||
19 | // Overriding `PartialEq` to use this strange notion of "equality" exposes | |
20 | // whether `match` is using structural-equality or method-dispatch | |
21 | // under the hood, which is the antithesis of rust-lang/rfcs#1445 | |
22 | impl PartialEq for B { | |
23 | fn eq(&self, other: &B) -> bool { std::cmp::min(self.0, other.0) == 0 } | |
24 | } | |
25 | ||
26 | fn main() { | |
27 | const RR_B0: & & B = & & B(0); | |
28 | const RR_B1: & & B = & & B(1); | |
29 | ||
30 | match RR_B0 { | |
31 | RR_B1 => { println!("CLAIM RR0: {:?} matches {:?}", RR_B1, RR_B0); } | |
32 | //~^ WARN must be annotated with `#[derive(PartialEq, Eq)]` | |
33 | //~| WARN will become a hard error in a future release | |
34 | _ => { } | |
35 | } | |
36 | ||
37 | match RR_B1 { | |
38 | RR_B1 => { println!("CLAIM RR1: {:?} matches {:?}", RR_B1, RR_B1); } | |
39 | //~^ WARN must be annotated with `#[derive(PartialEq, Eq)]` | |
40 | //~| WARN will become a hard error in a future release | |
41 | _ => { } | |
42 | } | |
43 | } |