From 175c78bc171fb400d1af4dda49ca14b58fb4534b Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 7 Jan 2020 15:06:23 +0900 Subject: [PATCH] Split up `collapsible_if` ui test --- tests/ui/collapsible_else_if.fixed | 66 ++++++++++++ tests/ui/collapsible_else_if.rs | 80 ++++++++++++++ tests/ui/collapsible_else_if.stderr | 154 +++++++++++++++++++++++++++ tests/ui/collapsible_if.fixed | 58 ----------- tests/ui/collapsible_if.rs | 72 ------------- tests/ui/collapsible_if.stderr | 155 +--------------------------- 6 files changed, 302 insertions(+), 283 deletions(-) create mode 100644 tests/ui/collapsible_else_if.fixed create mode 100644 tests/ui/collapsible_else_if.rs create mode 100644 tests/ui/collapsible_else_if.stderr diff --git a/tests/ui/collapsible_else_if.fixed b/tests/ui/collapsible_else_if.fixed new file mode 100644 index 00000000000..a31f748670c --- /dev/null +++ b/tests/ui/collapsible_else_if.fixed @@ -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!("!") +} +} diff --git a/tests/ui/collapsible_else_if.rs b/tests/ui/collapsible_else_if.rs new file mode 100644 index 00000000000..79a27aafc4d --- /dev/null +++ b/tests/ui/collapsible_else_if.rs @@ -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!("!") + } + } +} diff --git a/tests/ui/collapsible_else_if.stderr b/tests/ui/collapsible_else_if.stderr new file mode 100644 index 00000000000..26e3635c2d1 --- /dev/null +++ b/tests/ui/collapsible_else_if.stderr @@ -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 + diff --git a/tests/ui/collapsible_if.fixed b/tests/ui/collapsible_if.fixed index 810fd2e69ea..e8f90b3164a 100644 --- a/tests/ui/collapsible_if.fixed +++ b/tests/ui/collapsible_if.fixed @@ -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" { diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs index 7b322acae26..503cb35f858 100644 --- a/tests/ui/collapsible_if.rs +++ b/tests/ui/collapsible_if.rs @@ -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" { diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr index 16bc5a1c1b0..a204ccd4d82 100644 --- a/tests/ui/collapsible_if.stderr +++ b/tests/ui/collapsible_if.stderr @@ -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