summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/const_in_pattern/custom-eq-branch-warn.rs
blob: 856d204178d42b8d3ed289567e1412ea70d86d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// check-pass

struct CustomEq;

impl Eq for CustomEq {}
impl PartialEq for CustomEq {
    fn eq(&self, _: &Self) -> bool {
        false
    }
}

#[derive(PartialEq, Eq)]
enum Foo {
    Bar,
    Baz,
    Qux(CustomEq),
}

// We know that `BAR_BAZ` will always be `Foo::Bar` and thus eligible for structural matching, but
// dataflow will be more conservative.
const BAR_BAZ: Foo = if 42 == 42 {
    Foo::Bar
} else {
    Foo::Qux(CustomEq)
};

fn main() {
    match Foo::Qux(CustomEq) {
        BAR_BAZ => panic!(),
        //~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
        //~| WARN this was previously accepted
        //~| NOTE see issue #73448
        //~| NOTE `#[warn(nontrivial_structural_match)]` on by default
        _ => {}
    }
}