]> 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 1bc866010fd1956091271443be6084b56dcdddab..e216a9ee54c90ee959415569eb612f1a8010dfb9 100644 (file)
@@ -1,16 +1,7 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-
-
-
+// run-rustfix
+#![allow(clippy::assertions_on_constants, clippy::equatable_if_let)]
 
+#[rustfmt::skip]
 #[warn(clippy::collapsible_if)]
 fn main() {
     let x = "hello";
@@ -51,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" {
@@ -153,7 +72,7 @@ fn main() {
     }
 
 
-    // The following tests check for the fix of https://github.com/rust-lang-nursery/rust-clippy/issues/798
+    // The following tests check for the fix of https://github.com/rust-lang/rust-clippy/issues/798
     if x == "hello" {// Not collapsible
         if y == "world" {
             println!("Hello world!");
@@ -209,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!");
+        }
+    }
 }