2 #![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
5 #[warn(clippy::collapsible_if)]
11 println!("Hello world!");
15 if x == "hello" || x == "world" {
16 if y == "world" || y == "hello" {
17 println!("Hello world!");
21 if x == "hello" && x == "world" {
22 if y == "world" || y == "hello" {
23 println!("Hello world!");
27 if x == "hello" || x == "world" {
28 if y == "world" && y == "hello" {
29 println!("Hello world!");
33 if x == "hello" && x == "world" {
34 if y == "world" && y == "hello" {
35 println!("Hello world!");
45 // Collapse `else { if .. }` to `else if ..`
57 if let Some(42) = Some(42) {
76 if let Some(42) = Some(42) {
84 if let Some(42) = Some(42) {
87 if let Some(42) = Some(42) {
95 if let Some(42) = Some(42) {
106 if let Some(42) = Some(42) {
109 if let Some(42) = Some(42) {
117 // Works because any if with an else statement cannot be collapsed.
120 println!("Hello world!");
123 println!("Not Hello world");
128 println!("Hello world!");
130 println!("Hello something else");
143 assert!(true); // assert! is just an `if`
147 // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
148 if x == "hello" {// Not collapsible
150 println!("Hello world!");
154 if x == "hello" { // Not collapsible
156 println!("Hello world!");
163 println!("Hello world!");
168 if y == "world" { // Collapsible
169 println!("Hello world!");
186 if let Some(42) = Some(42) {
192 /* Not collapsible */
194 println!("Hello world!");
198 if x == "hello" { /* Not collapsible */
200 println!("Hello world!");
204 // Test behavior wrt. `let_chains`.
205 // None of the cases below should be collapsed.
206 fn truth() -> bool { true }