2 #![allow(clippy::assertions_on_constants)]
5 #[warn(clippy::collapsible_if)]
9 if x == "hello" && y == "world" {
10 println!("Hello world!");
13 if (x == "hello" || x == "world") && (y == "world" || y == "hello") {
14 println!("Hello world!");
17 if x == "hello" && x == "world" && (y == "world" || y == "hello") {
18 println!("Hello world!");
21 if (x == "hello" || x == "world") && y == "world" && y == "hello" {
22 println!("Hello world!");
25 if x == "hello" && x == "world" && y == "world" && y == "hello" {
26 println!("Hello world!");
29 if 42 == 1337 && 'a' != 'A' {
33 // Works because any if with an else statement cannot be collapsed.
36 println!("Hello world!");
39 println!("Not Hello world");
44 println!("Hello world!");
46 println!("Hello something else");
59 assert!(true); // assert! is just an `if`
63 // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
64 if x == "hello" {// Not collapsible
66 println!("Hello world!");
70 if x == "hello" { // Not collapsible
72 println!("Hello world!");
79 println!("Hello world!");
83 if x == "hello" && y == "world" { // Collapsible
84 println!("Hello world!");
100 if let Some(42) = Some(42) {
106 /* Not collapsible */
108 println!("Hello world!");
112 if x == "hello" { /* Not collapsible */
114 println!("Hello world!");
118 // Test behavior wrt. `let_chains`.
119 // None of the cases below should be collapsed.
120 fn truth() -> bool { true }
140 if matches!(true, true) && matches!(true, true) {}