summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/collapsible_else_if.fixed
blob: ce2a1c28c8a80f84c3ab0454d2efc517efa4f7c5 (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
// run-rustfix
#![allow(clippy::assertions_on_constants)]

#[rustfmt::skip]
#[warn(clippy::collapsible_if)]
fn main() {
    let x = "hello";
    let y = "world";
    // Collapse `else { if .. }` to `else if ..`
    if x == "hello" {
        print!("Hello ");
    } else if y == "world" {
        println!("world!")
    }

    if x == "hello" {
        print!("Hello ");
    } else if let Some(42) = Some(42) {
        println!("world!")
    }

    if x == "hello" {
        print!("Hello ");
    } else if y == "world" {
        println!("world")
    }
    else {
        println!("!")
    }

    if x == "hello" {
        print!("Hello ");
    } else if let Some(42) = Some(42) {
        println!("world")
    }
    else {
        println!("!")
    }

    if let Some(42) = Some(42) {
        print!("Hello ");
    } else if let Some(42) = Some(42) {
        println!("world")
    }
    else {
        println!("!")
    }

    if let Some(42) = Some(42) {
        print!("Hello ");
    } else if x == "hello" {
        println!("world")
    }
    else {
        println!("!")
    }

    if let Some(42) = Some(42) {
        print!("Hello ");
    } else if let Some(42) = Some(42) {
        println!("world")
    }
    else {
        println!("!")
    }
}