fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1#![allow( 2 clippy::assertions_on_constants, 3 clippy::equatable_if_let, 4 clippy::needless_if, 5 clippy::nonminimal_bool, 6 clippy::eq_op 7)] 8 9#[rustfmt::skip] 10#[warn(clippy::collapsible_if)] 11fn main() { 12 let x = "hello"; 13 let y = "world"; 14 if x == "hello" && y == "world" { 15 println!("Hello world!"); 16 } 17 18 if (x == "hello" || x == "world") && (y == "world" || y == "hello") { 19 println!("Hello world!"); 20 } 21 22 if x == "hello" && x == "world" && (y == "world" || y == "hello") { 23 println!("Hello world!"); 24 } 25 26 if (x == "hello" || x == "world") && y == "world" && y == "hello" { 27 println!("Hello world!"); 28 } 29 30 if x == "hello" && x == "world" && y == "world" && y == "hello" { 31 println!("Hello world!"); 32 } 33 34 if 42 == 1337 && 'a' != 'A' { 35 println!("world!") 36 } 37 38 // Works because any if with an else statement cannot be collapsed. 39 if x == "hello" { 40 if y == "world" { 41 println!("Hello world!"); 42 } 43 } else { 44 println!("Not Hello world"); 45 } 46 47 if x == "hello" { 48 if y == "world" { 49 println!("Hello world!"); 50 } else { 51 println!("Hello something else"); 52 } 53 } 54 55 if x == "hello" { 56 print!("Hello "); 57 if y == "world" { 58 println!("world!") 59 } 60 } 61 62 if true { 63 } else { 64 assert!(true); // assert! is just an `if` 65 } 66 67 68 // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798 69 if x == "hello" {// Not collapsible 70 if y == "world" { 71 println!("Hello world!"); 72 } 73 } 74 75 if x == "hello" { // Not collapsible 76 if y == "world" { 77 println!("Hello world!"); 78 } 79 } 80 81 if x == "hello" { 82 // Not collapsible 83 if y == "world" { 84 println!("Hello world!"); 85 } 86 } 87 88 if x == "hello" && y == "world" { // Collapsible 89 println!("Hello world!"); 90 } 91 92 if x == "hello" { 93 print!("Hello "); 94 } else { 95 // Not collapsible 96 if y == "world" { 97 println!("world!") 98 } 99 } 100 101 if x == "hello" { 102 print!("Hello "); 103 } else { 104 // Not collapsible 105 if let Some(42) = Some(42) { 106 println!("world!") 107 } 108 } 109 110 if x == "hello" { 111 /* Not collapsible */ 112 if y == "world" { 113 println!("Hello world!"); 114 } 115 } 116 117 if x == "hello" { /* Not collapsible */ 118 if y == "world" { 119 println!("Hello world!"); 120 } 121 } 122 123 // Test behavior wrt. `let_chains`. 124 // None of the cases below should be collapsed. 125 fn truth() -> bool { true } 126 127 // Prefix: 128 if let 0 = 1 { 129 if truth() {} 130 } 131 132 // Suffix: 133 if truth() { 134 if let 0 = 1 {} 135 } 136 137 // Midfix: 138 if truth() { 139 if let 0 = 1 { 140 if truth() {} 141 } 142 } 143 144 // Fix #5962 145 if matches!(true, true) && matches!(true, true) {} 146 147 // Issue #9375 148 if matches!(true, true) && truth() && matches!(true, true) {} 149 150 if true { 151 #[cfg(not(teehee))] 152 if true { 153 println!("Hello world!"); 154 } 155 } 156}