]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/collapsible_if.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / collapsible_if.rs
index f482d7704def92b7103bc9dafb6251944feb84c2..e216a9ee54c90ee959415569eb612f1a8010dfb9 100644 (file)
@@ -1,5 +1,5 @@
 // run-rustfix
-#![allow(clippy::cyclomatic_complexity)]
+#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
 
 #[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,42 @@ 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() {}
+        }
+    }
+
+    // Fix #5962
+    if matches!(true, true) {
+        if matches!(true, true) {}
+    }
+
+    // Issue #9375
+    if matches!(true, true) && truth() {
+        if matches!(true, true) {}
+    }
+
+    if true {
+        #[cfg(not(teehee))]
+        if true {
+            println!("Hello world!");
+        }
+    }
 }