summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/pattern_type_mismatch/pattern_alternatives.rs
blob: 558d496ae2c0f796b1c425ad018fc0ff57757a6f (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
#![allow(clippy::all)]
#![warn(clippy::pattern_type_mismatch)]

fn main() {}

fn alternatives() {
    enum Value<'a> {
        Unused,
        A(&'a Option<i32>),
        B,
    }
    let ref_value = &Value::A(&Some(23));

    // not ok
    if let Value::B | Value::A(_) = ref_value {}
    //~^ ERROR: type of pattern does not match the expression type
    if let &Value::B | &Value::A(Some(_)) = ref_value {}
    //~^ ERROR: type of pattern does not match the expression type
    if let Value::B | Value::A(Some(_)) = *ref_value {}
    //~^ ERROR: type of pattern does not match the expression type

    // ok
    if let &Value::B | &Value::A(_) = ref_value {}
    if let Value::B | Value::A(_) = *ref_value {}
    if let &Value::B | &Value::A(&Some(_)) = ref_value {}
    if let Value::B | Value::A(&Some(_)) = *ref_value {}
}