about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/needless_bool_assign.rs
blob: c504f61f4dd1d2c30e1eca069dc599f06066dd75 (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
#![allow(unused)]
#![warn(clippy::needless_bool_assign)]

fn random() -> bool {
    true
}

fn main() {
    struct Data {
        field: bool,
    };
    let mut a = Data { field: false };
    if random() && random() {
        a.field = true;
    } else {
        a.field = false
    }
    //~^^^^^ needless_bool_assign
    if random() && random() {
        a.field = false;
    } else {
        a.field = true
    }
    //~^^^^^ needless_bool_assign
    // Do not lint…
    if random() {
        a.field = false;
    } else {
        // …to avoid losing this comment
        a.field = true
    }
    // This one also triggers lint `clippy::if_same_then_else`
    // which does not suggest a rewrite.
    if random() {
        a.field = true;
    } else {
        a.field = true;
    }
    //~^^^^^ if_same_then_else
    //~| needless_bool_assign
    let mut b = false;
    if random() {
        a.field = false;
    } else {
        b = true;
    }
}

fn issue15063(x: bool, y: bool) {
    let mut z = false;

    if x && y {
        todo!()
    } else if x || y {
        z = true;
    } else {
        z = false;
    }
    //~^^^^^ needless_bool_assign
}