about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/if_not_else.rs
blob: 6cd2e3bd63fe96a0c2d0abc61c209de725ecb144 (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
77
78
#![warn(clippy::if_not_else)]

fn foo() -> bool {
    unimplemented!()
}
fn bla() -> bool {
    unimplemented!()
}

fn main() {
    if !bla() {
        //~^ if_not_else

        println!("Bugs");
    } else {
        println!("Bunny");
    }
    if 4 != 5 {
        //~^ if_not_else

        println!("Bugs");
    } else {
        println!("Bunny");
    }
    if !foo() {
        println!("Foo");
    } else if !bla() {
        println!("Bugs");
    } else {
        println!("Bunny");
    }

    if !(foo() && bla()) {
        //~^ if_not_else
        #[cfg(not(debug_assertions))]
        println!("not debug");
        #[cfg(debug_assertions)]
        println!("debug");
        if foo() {
            println!("foo");
        } else if bla() {
            println!("bla");
        } else {
            println!("both false");
        }
    } else {
        println!("both true");
    }
}

fn with_comments() {
    if !foo() {
        //~^ if_not_else
        /* foo is false */
        println!("foo is false");
    } else {
        println!("foo"); /* foo */
    }

    if !bla() {
        //~^ if_not_else
        // bla is false
        println!("bla");
    } else {
        println!("bla"); // bla
    }
}

fn with_annotations() {
    #[cfg(debug_assertions)]
    if !foo() {
        //~^ if_not_else
        /* foo is false */
        println!("foo is false");
    } else {
        println!("foo"); /* foo */
    }
}