about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/short_circuit_statement.fixed
blob: 133d296e259cf91231ef0d9e24c8ebf73062b1e2 (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
#![warn(clippy::short_circuit_statement)]
#![allow(clippy::nonminimal_bool)]

fn main() {
    if f() { g(); }
    //~^ short_circuit_statement

    if !f() { g(); }
    //~^ short_circuit_statement

    if 1 != 2 { g(); }
    //~^ short_circuit_statement

    if f() || g() { H * 2; }
    //~^ short_circuit_statement

    if !(f() || g()) { H * 2; }
    //~^ short_circuit_statement

    macro_rules! mac {
        ($f:ident or $g:ident) => {
            $f() || $g()
        };
        ($f:ident and $g:ident) => {
            $f() && $g()
        };
        () => {
            f() && g()
        };
    }

    if mac!() { mac!(); }
    //~^ short_circuit_statement

    if !mac!() { mac!(); }
    //~^ short_circuit_statement

    // Do not lint if the expression comes from a macro
    mac!();
}

fn f() -> bool {
    true
}

fn g() -> bool {
    false
}

struct H;

impl std::ops::Mul<u32> for H {
    type Output = bool;
    fn mul(self, other: u32) -> Self::Output {
        true
    }
}