about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJeremy Stucki <stucki.jeremy@gmail.com>2019-08-14 19:34:50 +0200
committerJeremy Stucki <stucki.jeremy@gmail.com>2019-08-14 19:34:50 +0200
commit214d4991038d0fef99efbb0fc8899bc7f003d7c1 (patch)
tree8b624599913737865f8fdad3a297b4b78dc8517d
parentdbe2bb4256527f9e3e55c0fa59fa7e099a7e8759 (diff)
downloadrust-214d4991038d0fef99efbb0fc8899bc7f003d7c1.tar.gz
rust-214d4991038d0fef99efbb0fc8899bc7f003d7c1.zip
Add multiline test
-rw-r--r--tests/ui/unnecessary_fold.fixed8
-rw-r--r--tests/ui/unnecessary_fold.rs8
-rw-r--r--tests/ui/unnecessary_fold.stderr8
3 files changed, 23 insertions, 1 deletions
diff --git a/tests/ui/unnecessary_fold.fixed b/tests/ui/unnecessary_fold.fixed
index 5f12d72a76a..52300a3b640 100644
--- a/tests/ui/unnecessary_fold.fixed
+++ b/tests/ui/unnecessary_fold.fixed
@@ -41,4 +41,12 @@ fn unnecessary_fold_should_ignore() {
     let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
 }
 
+/// Should lint only the line containing the fold
+fn unnecessary_fold_over_multiple_lines() {
+    let _ = (0..3)
+        .map(|x| x + 1)
+        .filter(|x| x % 2 == 0)
+        .any(|x| x > 2);
+}
+
 fn main() {}
diff --git a/tests/ui/unnecessary_fold.rs b/tests/ui/unnecessary_fold.rs
index ae667d1ac06..4028d80c0a3 100644
--- a/tests/ui/unnecessary_fold.rs
+++ b/tests/ui/unnecessary_fold.rs
@@ -41,4 +41,12 @@ fn unnecessary_fold_should_ignore() {
     let _ = [(0..2), (0..3)].iter().fold(1, |a, b| a * b.len());
 }
 
+/// Should lint only the line containing the fold
+fn unnecessary_fold_over_multiple_lines() {
+    let _ = (0..3)
+        .map(|x| x + 1)
+        .filter(|x| x % 2 == 0)
+        .fold(false, |acc, x| acc || x > 2);
+}
+
 fn main() {}
diff --git a/tests/ui/unnecessary_fold.stderr b/tests/ui/unnecessary_fold.stderr
index f9911d4a3dc..3282b3d9a70 100644
--- a/tests/ui/unnecessary_fold.stderr
+++ b/tests/ui/unnecessary_fold.stderr
@@ -30,5 +30,11 @@ error: this `.fold` can be written more succinctly using another method
 LL |     let _: bool = (0..3).map(|x| 2 * x).fold(false, |acc, x| acc || x > 2);
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `.any(|x| x > 2)`
 
-error: aborting due to 5 previous errors
+error: this `.fold` can be written more succinctly using another method
+  --> $DIR/unnecessary_fold.rs:49:10
+   |
+LL |         .fold(false, |acc, x| acc || x > 2);
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `any(|x| x > 2)`
+
+error: aborting due to 6 previous errors