2023-04-23 06:03:09 -05:00
|
|
|
//@run-rustfix
|
2023-05-20 08:39:26 -05:00
|
|
|
#![allow(
|
|
|
|
clippy::assertions_on_constants,
|
|
|
|
clippy::equatable_if_let,
|
2023-07-02 07:35:19 -05:00
|
|
|
clippy::needless_if,
|
2023-05-20 08:39:26 -05:00
|
|
|
clippy::nonminimal_bool,
|
|
|
|
clippy::eq_op
|
|
|
|
)]
|
2019-01-13 04:44:45 -06:00
|
|
|
|
2018-12-08 11:56:59 -06:00
|
|
|
#[rustfmt::skip]
|
2018-07-28 10:34:52 -05:00
|
|
|
#[warn(clippy::collapsible_if)]
|
2015-05-29 09:07:34 -05:00
|
|
|
fn main() {
|
|
|
|
let x = "hello";
|
|
|
|
let y = "world";
|
2016-06-07 11:32:26 -05:00
|
|
|
if x == "hello" {
|
2015-05-29 09:07:34 -05:00
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 11:32:26 -05:00
|
|
|
if x == "hello" || x == "world" {
|
2015-05-29 09:07:34 -05:00
|
|
|
if y == "world" || y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-29 14:26:26 -05:00
|
|
|
if x == "hello" && x == "world" {
|
|
|
|
if y == "world" || y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" || x == "world" {
|
|
|
|
if y == "world" && y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" && x == "world" {
|
|
|
|
if y == "world" && y == "hello" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if 42 == 1337 {
|
|
|
|
if 'a' != 'A' {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-29 09:07:34 -05:00
|
|
|
// Works because any if with an else statement cannot be collapsed.
|
|
|
|
if x == "hello" {
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
println!("Not Hello world");
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
} else {
|
|
|
|
println!("Hello something else");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-11 13:22:20 -05:00
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
if y == "world" {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
2016-07-01 10:41:57 -05:00
|
|
|
|
|
|
|
if true {
|
|
|
|
} else {
|
|
|
|
assert!(true); // assert! is just an `if`
|
|
|
|
}
|
2018-10-16 15:20:27 -05:00
|
|
|
|
|
|
|
|
2018-11-21 21:40:09 -06:00
|
|
|
// The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
|
2018-10-16 15:20:27 -05:00
|
|
|
if x == "hello" {// Not collapsible
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" { // Not collapsible
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
// Not collapsible
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
if y == "world" { // Collapsible
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
// Not collapsible
|
|
|
|
if y == "world" {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
print!("Hello ");
|
|
|
|
} else {
|
|
|
|
// Not collapsible
|
|
|
|
if let Some(42) = Some(42) {
|
|
|
|
println!("world!")
|
|
|
|
}
|
|
|
|
}
|
2018-10-18 11:57:16 -05:00
|
|
|
|
|
|
|
if x == "hello" {
|
|
|
|
/* Not collapsible */
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if x == "hello" { /* Not collapsible */
|
|
|
|
if y == "world" {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
2019-05-21 01:17:47 -05:00
|
|
|
|
|
|
|
// Test behavior wrt. `let_chains`.
|
|
|
|
// None of the cases below should be collapsed.
|
|
|
|
fn truth() -> bool { true }
|
|
|
|
|
|
|
|
// Prefix:
|
|
|
|
if let 0 = 1 {
|
|
|
|
if truth() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Suffix:
|
|
|
|
if truth() {
|
|
|
|
if let 0 = 1 {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Midfix:
|
|
|
|
if truth() {
|
|
|
|
if let 0 = 1 {
|
|
|
|
if truth() {}
|
|
|
|
}
|
|
|
|
}
|
2020-09-10 10:47:07 -05:00
|
|
|
|
|
|
|
// Fix #5962
|
|
|
|
if matches!(true, true) {
|
|
|
|
if matches!(true, true) {}
|
|
|
|
}
|
2021-02-25 04:25:22 -06:00
|
|
|
|
2022-09-21 12:02:37 -05:00
|
|
|
// Issue #9375
|
|
|
|
if matches!(true, true) && truth() {
|
|
|
|
if matches!(true, true) {}
|
|
|
|
}
|
|
|
|
|
2021-02-25 04:25:22 -06:00
|
|
|
if true {
|
|
|
|
#[cfg(not(teehee))]
|
|
|
|
if true {
|
|
|
|
println!("Hello world!");
|
|
|
|
}
|
|
|
|
}
|
2015-05-29 09:07:34 -05:00
|
|
|
}
|