]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/collapsible_if.rs
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / collapsible_if.rs
index 1bc866010fd1956091271443be6084b56dcdddab..7b322acae263d75eed3482dd120150677faf7b47 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::cognitive_complexity, clippy::assertions_on_constants)]
 
+#[rustfmt::skip]
 #[warn(clippy::collapsible_if)]
 fn main() {
     let x = "hello";
@@ -153,7 +144,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 +200,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() {}
+        }
+    }
 }