about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/filter_map_next.rs3
-rw-r--r--tests/ui/filter_map_next.stderr14
-rw-r--r--tests/ui/filter_map_next_fixable.fixed10
-rw-r--r--tests/ui/filter_map_next_fixable.rs10
-rw-r--r--tests/ui/filter_map_next_fixable.stderr10
-rw-r--r--tests/ui/methods.rs5
-rw-r--r--tests/ui/methods.stderr30
-rw-r--r--tests/ui/methods_fixable.fixed11
-rw-r--r--tests/ui/methods_fixable.rs11
-rw-r--r--tests/ui/methods_fixable.stderr10
10 files changed, 79 insertions, 35 deletions
diff --git a/tests/ui/filter_map_next.rs b/tests/ui/filter_map_next.rs
index f5d051be198..dbeb2354309 100644
--- a/tests/ui/filter_map_next.rs
+++ b/tests/ui/filter_map_next.rs
@@ -3,9 +3,6 @@
 fn main() {
     let a = ["1", "lol", "3", "NaN", "5"];
 
-    let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
-    assert_eq!(element, Some(1));
-
     #[rustfmt::skip]
     let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
         .into_iter()
diff --git a/tests/ui/filter_map_next.stderr b/tests/ui/filter_map_next.stderr
index bcedf11e536..45427684d96 100644
--- a/tests/ui/filter_map_next.stderr
+++ b/tests/ui/filter_map_next.stderr
@@ -1,13 +1,5 @@
 error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
-  --> $DIR/filter_map_next.rs:6:32
-   |
-LL |     let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
-   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
-   |
-   = note: `-D clippy::filter-map-next` implied by `-D warnings`
-
-error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
-  --> $DIR/filter_map_next.rs:10:26
+  --> $DIR/filter_map_next.rs:7:26
    |
 LL |       let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
    |  __________________________^
@@ -18,6 +10,8 @@ LL | |             if x == 2 {
 LL | |         })
 LL | |         .next();
    | |_______________^
+   |
+   = note: `-D clippy::filter-map-next` implied by `-D warnings`
 
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
diff --git a/tests/ui/filter_map_next_fixable.fixed b/tests/ui/filter_map_next_fixable.fixed
new file mode 100644
index 00000000000..c3992d7e92c
--- /dev/null
+++ b/tests/ui/filter_map_next_fixable.fixed
@@ -0,0 +1,10 @@
+// run-rustfix
+
+#![warn(clippy::all, clippy::pedantic)]
+
+fn main() {
+    let a = ["1", "lol", "3", "NaN", "5"];
+
+    let element: Option<i32> = a.iter().find_map(|s| s.parse().ok());
+    assert_eq!(element, Some(1));
+}
diff --git a/tests/ui/filter_map_next_fixable.rs b/tests/ui/filter_map_next_fixable.rs
new file mode 100644
index 00000000000..447219a9683
--- /dev/null
+++ b/tests/ui/filter_map_next_fixable.rs
@@ -0,0 +1,10 @@
+// run-rustfix
+
+#![warn(clippy::all, clippy::pedantic)]
+
+fn main() {
+    let a = ["1", "lol", "3", "NaN", "5"];
+
+    let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
+    assert_eq!(element, Some(1));
+}
diff --git a/tests/ui/filter_map_next_fixable.stderr b/tests/ui/filter_map_next_fixable.stderr
new file mode 100644
index 00000000000..6c2530e0379
--- /dev/null
+++ b/tests/ui/filter_map_next_fixable.stderr
@@ -0,0 +1,10 @@
+error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
+  --> $DIR/filter_map_next_fixable.rs:8:32
+   |
+LL |     let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
+   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
+   |
+   = note: `-D clippy::filter-map-next` implied by `-D warnings`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs
index 80dd2f744b3..d93e5b114ec 100644
--- a/tests/ui/methods.rs
+++ b/tests/ui/methods.rs
@@ -122,16 +122,13 @@ impl Mul<T> for T {
 fn filter_next() {
     let v = vec![3, 2, 1, 0, -1, -2, -3];
 
-    // Single-line case.
-    let _ = v.iter().filter(|&x| *x < 0).next();
-
     // Multi-line case.
     let _ = v.iter().filter(|&x| {
                                 *x < 0
                             }
                    ).next();
 
-    // Check that hat we don't lint if the caller is not an `Iterator`.
+    // Check that we don't lint if the caller is not an `Iterator`.
     let foo = IteratorFalsePositives { foo: 0 };
     let _ = foo.filter().next();
 }
diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr
index 2df1941aaaa..8a281c2dbd2 100644
--- a/tests/ui/methods.stderr
+++ b/tests/ui/methods.stderr
@@ -11,23 +11,17 @@ LL | |     }
 error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
   --> $DIR/methods.rs:126:13
    |
-LL |     let _ = v.iter().filter(|&x| *x < 0).next();
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `v.iter().find(|&x| *x < 0)`
-   |
-   = note: `-D clippy::filter-next` implied by `-D warnings`
-
-error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
-  --> $DIR/methods.rs:129:13
-   |
 LL |       let _ = v.iter().filter(|&x| {
    |  _____________^
 LL | |                                 *x < 0
 LL | |                             }
 LL | |                    ).next();
    | |___________________________^
+   |
+   = note: `-D clippy::filter-next` implied by `-D warnings`
 
 error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:146:22
+  --> $DIR/methods.rs:143:22
    |
 LL |     let _ = v.iter().find(|&x| *x < 0).is_some();
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x < 0)`
@@ -35,25 +29,25 @@ LL |     let _ = v.iter().find(|&x| *x < 0).is_some();
    = note: `-D clippy::search-is-some` implied by `-D warnings`
 
 error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:147:20
+  --> $DIR/methods.rs:144:20
    |
 LL |     let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| **y == x)`
 
 error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:148:20
+  --> $DIR/methods.rs:145:20
    |
 LL |     let _ = (0..1).find(|x| *x == 0).is_some();
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| x == 0)`
 
 error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:149:22
+  --> $DIR/methods.rs:146:22
    |
 LL |     let _ = v.iter().find(|x| **x == 0).is_some();
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x == 0)`
 
 error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:152:13
+  --> $DIR/methods.rs:149:13
    |
 LL |       let _ = v.iter().find(|&x| {
    |  _____________^
@@ -63,13 +57,13 @@ LL | |                    ).is_some();
    | |______________________________^
 
 error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:158:22
+  --> $DIR/methods.rs:155:22
    |
 LL |     let _ = v.iter().position(|&x| x < 0).is_some();
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
 
 error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:161:13
+  --> $DIR/methods.rs:158:13
    |
 LL |       let _ = v.iter().position(|&x| {
    |  _____________^
@@ -79,13 +73,13 @@ LL | |                    ).is_some();
    | |______________________________^
 
 error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:167:22
+  --> $DIR/methods.rs:164:22
    |
 LL |     let _ = v.iter().rposition(|&x| x < 0).is_some();
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
 
 error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
-  --> $DIR/methods.rs:170:13
+  --> $DIR/methods.rs:167:13
    |
 LL |       let _ = v.iter().rposition(|&x| {
    |  _____________^
@@ -94,5 +88,5 @@ LL | |                                }
 LL | |                    ).is_some();
    | |______________________________^
 
-error: aborting due to 12 previous errors
+error: aborting due to 11 previous errors
 
diff --git a/tests/ui/methods_fixable.fixed b/tests/ui/methods_fixable.fixed
new file mode 100644
index 00000000000..ee7c1b0da6d
--- /dev/null
+++ b/tests/ui/methods_fixable.fixed
@@ -0,0 +1,11 @@
+// run-rustfix
+
+#![warn(clippy::filter_next)]
+
+/// Checks implementation of `FILTER_NEXT` lint.
+fn main() {
+    let v = vec![3, 2, 1, 0, -1, -2, -3];
+
+    // Single-line case.
+    let _ = v.iter().find(|&x| *x < 0);
+}
diff --git a/tests/ui/methods_fixable.rs b/tests/ui/methods_fixable.rs
new file mode 100644
index 00000000000..6d0f1b7bd51
--- /dev/null
+++ b/tests/ui/methods_fixable.rs
@@ -0,0 +1,11 @@
+// run-rustfix
+
+#![warn(clippy::filter_next)]
+
+/// Checks implementation of `FILTER_NEXT` lint.
+fn main() {
+    let v = vec![3, 2, 1, 0, -1, -2, -3];
+
+    // Single-line case.
+    let _ = v.iter().filter(|&x| *x < 0).next();
+}
diff --git a/tests/ui/methods_fixable.stderr b/tests/ui/methods_fixable.stderr
new file mode 100644
index 00000000000..70e7c3dea54
--- /dev/null
+++ b/tests/ui/methods_fixable.stderr
@@ -0,0 +1,10 @@
+error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
+  --> $DIR/methods_fixable.rs:10:13
+   |
+LL |     let _ = v.iter().filter(|&x| *x < 0).next();
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `v.iter().find(|&x| *x < 0)`
+   |
+   = note: `-D clippy::filter-next` implied by `-D warnings`
+
+error: aborting due to previous error
+