summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/needless_bitwise_bool.fixed
blob: 5e1ea663a1077b8a5a69e4b5d1281dc5c6bac500 (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
// run-rustfix

#![warn(clippy::needless_bitwise_bool)]

fn returns_bool() -> bool {
    true
}

const fn const_returns_bool() -> bool {
    false
}

fn main() {
    let (x, y) = (false, true);
    if x & y {
        println!("true")
    }
    if returns_bool() & x {
        println!("true")
    }
    if !returns_bool() & returns_bool() {
        println!("true")
    }
    if y && !x {
        println!("true")
    }

    // BELOW: lints we hope to catch as `Expr::can_have_side_effects` improves.
    if y & !const_returns_bool() {
        println!("true") // This is a const function, in an UnOp
    }

    if y & "abcD".is_empty() {
        println!("true") // This is a const method call
    }

    if y & (0 < 1) {
        println!("true") // This is a BinOp with no side effects
    }
}