Move fixable filter_next and filter_map_next cases to rustfixed tests

This commit is contained in:
ThibsG 2020-10-23 09:49:47 +02:00
parent 2a3ae11485
commit e2d86b5b80
10 changed files with 79 additions and 35 deletions

View file

@ -3,9 +3,6 @@
fn main() { fn main() {
let a = ["1", "lol", "3", "NaN", "5"]; 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] #[rustfmt::skip]
let _: Option<u32> = vec![1, 2, 3, 4, 5, 6] let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
.into_iter() .into_iter()

View file

@ -1,13 +1,5 @@
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead. 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 --> $DIR/filter_map_next.rs:7:26
|
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
| |
LL | let _: Option<u32> = vec![1, 2, 3, 4, 5, 6] LL | let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
| __________________________^ | __________________________^
@ -18,6 +10,8 @@ LL | | if x == 2 {
LL | | }) LL | | })
LL | | .next(); 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

View file

@ -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));
}

View file

@ -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));
}

View file

@ -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

View file

@ -122,16 +122,13 @@ impl Mul<T> for T {
fn filter_next() { fn filter_next() {
let v = vec![3, 2, 1, 0, -1, -2, -3]; let v = vec![3, 2, 1, 0, -1, -2, -3];
// Single-line case.
let _ = v.iter().filter(|&x| *x < 0).next();
// Multi-line case. // Multi-line case.
let _ = v.iter().filter(|&x| { let _ = v.iter().filter(|&x| {
*x < 0 *x < 0
} }
).next(); ).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 = IteratorFalsePositives { foo: 0 };
let _ = foo.filter().next(); let _ = foo.filter().next();
} }

View file

@ -11,23 +11,17 @@ LL | | }
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead. error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
--> $DIR/methods.rs:126:13 --> $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 | let _ = v.iter().filter(|&x| {
| _____________^ | _____________^
LL | | *x < 0 LL | | *x < 0
LL | | } LL | | }
LL | | ).next(); 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()`. 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(); LL | let _ = v.iter().find(|&x| *x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x < 0)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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` = 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()`. 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 LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| **y == x)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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()`. 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(); LL | let _ = (0..1).find(|x| *x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| x == 0)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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()`. 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(); LL | let _ = v.iter().find(|x| **x == 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x == 0)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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()`. 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| { 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()`. 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(); LL | let _ = v.iter().position(|&x| x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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()`. 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| { 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()`. 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(); LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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()`. 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| { LL | let _ = v.iter().rposition(|&x| {
| _____________^ | _____________^
@ -94,5 +88,5 @@ LL | | }
LL | | ).is_some(); LL | | ).is_some();
| |______________________________^ | |______________________________^
error: aborting due to 12 previous errors error: aborting due to 11 previous errors

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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