]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/collapsible_if.rs
iterate List by value
[rust.git] / tests / ui / collapsible_if.rs
index 5dac42a3dd976aaf500ca991ccbed612a79a4c2e..dc9d9b451c0f9620d9181936ebbc18bd58fa6a4f 100644 (file)
@@ -1,5 +1,5 @@
 // run-rustfix
-#![allow(clippy::cognitive_complexity, clippy::assertions_on_constants)]
+#![allow(clippy::assertions_on_constants)]
 
 #[rustfmt::skip]
 #[warn(clippy::collapsible_if)]
@@ -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" {
@@ -200,4 +128,25 @@ fn main() {
             println!("Hello world!");
         }
     }
+
+    // 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() {}
+        }
+    }
 }