2 #![allow(clippy::cognitive_complexity, 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 // Collapse `else { if .. }` to `else if ..`
36 } else if y == "world" {
42 } else if let Some(42) = Some(42) {
48 } else if y == "world" {
57 } else if let Some(42) = Some(42) {
64 if let Some(42) = Some(42) {
66 } else if let Some(42) = Some(42) {
73 if let Some(42) = Some(42) {
75 } else if x == "hello" {
82 if let Some(42) = Some(42) {
84 } else if let Some(42) = Some(42) {
91 // Works because any if with an else statement cannot be collapsed.
94 println!("Hello world!");
97 println!("Not Hello world");
102 println!("Hello world!");
104 println!("Hello something else");
117 assert!(true); // assert! is just an `if`
121 // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
122 if x == "hello" {// Not collapsible
124 println!("Hello world!");
128 if x == "hello" { // Not collapsible
130 println!("Hello world!");
137 println!("Hello world!");
141 if x == "hello" && y == "world" { // Collapsible
142 println!("Hello world!");
158 if let Some(42) = Some(42) {
164 /* Not collapsible */
166 println!("Hello world!");
170 if x == "hello" { /* Not collapsible */
172 println!("Hello world!");