about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorLukas Stevens <mail@lukas-stevens.de>2018-10-16 22:20:27 +0200
committerLukas Stevens <mail@lukas-stevens.de>2018-10-18 18:00:21 +0200
commit8753e568bf0d8bdc591ca56d9c3bc442efffaede (patch)
tree56393267ee029c6db73f9a024646bf0cec478502 /tests
parent1264bb6b7d74095f7fb9221904bbc288ff21a3c3 (diff)
downloadrust-8753e568bf0d8bdc591ca56d9c3bc442efffaede.tar.gz
rust-8753e568bf0d8bdc591ca56d9c3bc442efffaede.zip
Check for comments in collapsible ifs
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/collapsible_if.rs45
-rw-r--r--tests/ui/collapsible_if.stderr18
2 files changed, 62 insertions, 1 deletions
diff --git a/tests/ui/collapsible_if.rs b/tests/ui/collapsible_if.rs
index a6df9109df9..c186d9e577f 100644
--- a/tests/ui/collapsible_if.rs
+++ b/tests/ui/collapsible_if.rs
@@ -151,4 +151,49 @@ fn main() {
     } else {
         assert!(true); // assert! is just an `if`
     }
+
+
+    // The following tests check for the fix of https://github.com/rust-lang-nursery/rust-clippy/issues/798
+    if x == "hello" {// Not collapsible
+        if y == "world" {
+            println!("Hello world!");
+        }
+    }
+
+    if x == "hello" { // Not collapsible
+        if y == "world" {
+            println!("Hello world!");
+        }
+    }
+
+    if x == "hello" {
+        // Not collapsible
+        if y == "world" {
+            println!("Hello world!");
+        }
+    }
+
+    if x == "hello" {
+        if y == "world" { // Collapsible
+            println!("Hello world!");
+        }
+    }
+
+    if x == "hello" {
+        print!("Hello ");
+    } else {
+        // Not collapsible
+        if y == "world" {
+            println!("world!")
+        }
+    }
+
+    if x == "hello" {
+        print!("Hello ");
+    } else {
+        // Not collapsible
+        if let Some(42) = Some(42) {
+            println!("world!")
+        }
+    }
 }
diff --git a/tests/ui/collapsible_if.stderr b/tests/ui/collapsible_if.stderr
index 87c279cd725..3f06dca5495 100644
--- a/tests/ui/collapsible_if.stderr
+++ b/tests/ui/collapsible_if.stderr
@@ -240,5 +240,21 @@ help: try
 122 | }
     |
 
-error: aborting due to 13 previous errors
+error: this if statement can be collapsed
+   --> $DIR/collapsible_if.rs:176:5
+    |
+176 | /     if x == "hello" {
+177 | |         if y == "world" { // Collapsible
+178 | |             println!("Hello world!");
+179 | |         }
+180 | |     }
+    | |_____^
+help: try
+    |
+176 |     if x == "hello" && y == "world" { // Collapsible
+177 |     println!("Hello world!");
+178 | }
+    |
+
+error: aborting due to 14 previous errors