Split up collapsible_if ui test

This commit is contained in:
Yuki Okushi 2020-01-07 15:06:23 +09:00
parent e8642c7a29
commit 175c78bc17
6 changed files with 302 additions and 283 deletions

View File

@ -0,0 +1,66 @@
// run-rustfix
#![allow(clippy::cognitive_complexity, 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!("!")
}
}

View File

@ -0,0 +1,80 @@
// run-rustfix
#![allow(clippy::cognitive_complexity, 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!("!")
}
}
}

View File

@ -0,0 +1,154 @@
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_else_if.rs:12:12
|
LL | } else {
| ____________^
LL | | if y == "world" {
LL | | println!("world!")
LL | | }
LL | | }
| |_____^
|
= note: `-D clippy::collapsible-if` implied by `-D warnings`
help: try
|
LL | } else if y == "world" {
LL | println!("world!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_else_if.rs:20:12
|
LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world!")
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if let Some(42) = Some(42) {
LL | println!("world!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_else_if.rs:28:12
|
LL | } else {
| ____________^
LL | | if y == "world" {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if y == "world" {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_else_if.rs:39:12
|
LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if let Some(42) = Some(42) {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_else_if.rs:50:12
|
LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if let Some(42) = Some(42) {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_else_if.rs:61:12
|
LL | } else {
| ____________^
LL | | if x == "hello" {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if x == "hello" {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_else_if.rs:72:12
|
LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if let Some(42) = Some(42) {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: aborting due to 7 previous errors

View File

@ -30,64 +30,6 @@ fn main() {
println!("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!("!")
}
// Works because any if with an else statement cannot be collapsed.
if x == "hello" {
if y == "world" {

View File

@ -42,78 +42,6 @@ fn main() {
}
}
// 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!("!")
}
}
// Works because any if with an else statement cannot be collapsed.
if x == "hello" {
if y == "world" {

View File

@ -101,159 +101,8 @@ LL | println!("world!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:48:12
|
LL | } else {
| ____________^
LL | | if y == "world" {
LL | | println!("world!")
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if y == "world" {
LL | println!("world!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:56:12
|
LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world!")
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if let Some(42) = Some(42) {
LL | println!("world!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:64:12
|
LL | } else {
| ____________^
LL | | if y == "world" {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if y == "world" {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:75:12
|
LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if let Some(42) = Some(42) {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:86:12
|
LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if let Some(42) = Some(42) {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:97:12
|
LL | } else {
| ____________^
LL | | if x == "hello" {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if x == "hello" {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this `else { if .. }` block can be collapsed
--> $DIR/collapsible_if.rs:108:12
|
LL | } else {
| ____________^
LL | | if let Some(42) = Some(42) {
LL | | println!("world")
LL | | }
... |
LL | | }
LL | | }
| |_____^
|
help: try
|
LL | } else if let Some(42) = Some(42) {
LL | println!("world")
LL | }
LL | else {
LL | println!("!")
LL | }
|
error: this if statement can be collapsed
--> $DIR/collapsible_if.rs:167:5
--> $DIR/collapsible_if.rs:95:5
|
LL | / if x == "hello" {
LL | | if y == "world" { // Collapsible
@ -269,5 +118,5 @@ LL | println!("Hello world!");
LL | }
|
error: aborting due to 14 previous errors
error: aborting due to 7 previous errors