about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/collapsible_if_let_chains.rs
blob: b2e88b1a55689882c8823460cd626b5c09d03db7 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//@revisions: edition2021 edition2024
//@[edition2021] edition:2021
//@[edition2024] edition:2024
//@[edition2021] check-pass

#![warn(clippy::collapsible_if)]

fn main() {
    if let Some(a) = Some(3) {
        // with comment, so do not lint
        if let Some(b) = Some(4) {
            let _ = a + b;
        }
    }

    //~[edition2024]v collapsible_if
    if let Some(a) = Some(3) {
        if let Some(b) = Some(4) {
            let _ = a + b;
        }
    }

    //~[edition2024]v collapsible_if
    if let Some(a) = Some(3) {
        if a + 1 == 4 {
            let _ = a;
        }
    }

    //~[edition2024]v collapsible_if
    if Some(3) == Some(4).map(|x| x - 1) {
        if let Some(b) = Some(4) {
            let _ = b;
        }
    }

    fn truth() -> bool {
        true
    }

    // Prefix:
    //~[edition2024]v collapsible_if
    if let 0 = 1 {
        if truth() {}
    }

    // Suffix:
    //~[edition2024]v collapsible_if
    if truth() {
        if let 0 = 1 {}
    }

    // Midfix:
    //~[edition2024]vvv collapsible_if
    //~[edition2024]v collapsible_if
    if truth() {
        if let 0 = 1 {
            if truth() {}
        }
    }
}

#[clippy::msrv = "1.87.0"]
fn msrv_1_87() {
    if let 0 = 1 {
        if true {}
    }
}

#[clippy::msrv = "1.88.0"]
fn msrv_1_88() {
    //~[edition2024]v collapsible_if
    if let 0 = 1 {
        if true {}
    }
}