Skip to content

Commit e2d86b5

Browse files
committed
Move fixable filter_next and filter_map_next cases to rustfixed tests
1 parent 2a3ae11 commit e2d86b5

10 files changed

+79
-35
lines changed

tests/ui/filter_map_next.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
fn main() {
44
let a = ["1", "lol", "3", "NaN", "5"];
55

6-
let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
7-
assert_eq!(element, Some(1));
8-
96
#[rustfmt::skip]
107
let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
118
.into_iter()

tests/ui/filter_map_next.stderr

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
2-
--> $DIR/filter_map_next.rs:6:32
3-
|
4-
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
6-
|
7-
= note: `-D clippy::filter-map-next` implied by `-D warnings`
8-
9-
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
10-
--> $DIR/filter_map_next.rs:10:26
2+
--> $DIR/filter_map_next.rs:7:26
113
|
124
LL | let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
135
| __________________________^
@@ -18,6 +10,8 @@ LL | | if x == 2 {
1810
LL | | })
1911
LL | | .next();
2012
| |_______________^
13+
|
14+
= note: `-D clippy::filter-map-next` implied by `-D warnings`
2115

22-
error: aborting due to 2 previous errors
16+
error: aborting due to previous error
2317

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-rustfix
2+
3+
#![warn(clippy::all, clippy::pedantic)]
4+
5+
fn main() {
6+
let a = ["1", "lol", "3", "NaN", "5"];
7+
8+
let element: Option<i32> = a.iter().find_map(|s| s.parse().ok());
9+
assert_eq!(element, Some(1));
10+
}

tests/ui/filter_map_next_fixable.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-rustfix
2+
3+
#![warn(clippy::all, clippy::pedantic)]
4+
5+
fn main() {
6+
let a = ["1", "lol", "3", "NaN", "5"];
7+
8+
let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
9+
assert_eq!(element, Some(1));
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: called `filter_map(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find_map(..)` instead.
2+
--> $DIR/filter_map_next_fixable.rs:8:32
3+
|
4+
LL | let element: Option<i32> = a.iter().filter_map(|s| s.parse().ok()).next();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `a.iter().find_map(|s| s.parse().ok())`
6+
|
7+
= note: `-D clippy::filter-map-next` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

tests/ui/methods.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,13 @@ impl Mul<T> for T {
122122
fn filter_next() {
123123
let v = vec![3, 2, 1, 0, -1, -2, -3];
124124

125-
// Single-line case.
126-
let _ = v.iter().filter(|&x| *x < 0).next();
127-
128125
// Multi-line case.
129126
let _ = v.iter().filter(|&x| {
130127
*x < 0
131128
}
132129
).next();
133130

134-
// Check that hat we don't lint if the caller is not an `Iterator`.
131+
// Check that we don't lint if the caller is not an `Iterator`.
135132
let foo = IteratorFalsePositives { foo: 0 };
136133
let _ = foo.filter().next();
137134
}

tests/ui/methods.stderr

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,43 @@ LL | | }
1111
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
1212
--> $DIR/methods.rs:126:13
1313
|
14-
LL | let _ = v.iter().filter(|&x| *x < 0).next();
15-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `v.iter().find(|&x| *x < 0)`
16-
|
17-
= note: `-D clippy::filter-next` implied by `-D warnings`
18-
19-
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
20-
--> $DIR/methods.rs:129:13
21-
|
2214
LL | let _ = v.iter().filter(|&x| {
2315
| _____________^
2416
LL | | *x < 0
2517
LL | | }
2618
LL | | ).next();
2719
| |___________________________^
20+
|
21+
= note: `-D clippy::filter-next` implied by `-D warnings`
2822

2923
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
30-
--> $DIR/methods.rs:146:22
24+
--> $DIR/methods.rs:143:22
3125
|
3226
LL | let _ = v.iter().find(|&x| *x < 0).is_some();
3327
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x < 0)`
3428
|
3529
= note: `-D clippy::search-is-some` implied by `-D warnings`
3630

3731
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
38-
--> $DIR/methods.rs:147:20
32+
--> $DIR/methods.rs:144:20
3933
|
4034
LL | let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
4135
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| **y == x)`
4236

4337
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
44-
--> $DIR/methods.rs:148:20
38+
--> $DIR/methods.rs:145:20
4539
|
4640
LL | let _ = (0..1).find(|x| *x == 0).is_some();
4741
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| x == 0)`
4842

4943
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
50-
--> $DIR/methods.rs:149:22
44+
--> $DIR/methods.rs:146:22
5145
|
5246
LL | let _ = v.iter().find(|x| **x == 0).is_some();
5347
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|x| *x == 0)`
5448

5549
error: called `is_some()` after searching an `Iterator` with find. This is more succinctly expressed by calling `any()`.
56-
--> $DIR/methods.rs:152:13
50+
--> $DIR/methods.rs:149:13
5751
|
5852
LL | let _ = v.iter().find(|&x| {
5953
| _____________^
@@ -63,13 +57,13 @@ LL | | ).is_some();
6357
| |______________________________^
6458

6559
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
66-
--> $DIR/methods.rs:158:22
60+
--> $DIR/methods.rs:155:22
6761
|
6862
LL | let _ = v.iter().position(|&x| x < 0).is_some();
6963
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
7064

7165
error: called `is_some()` after searching an `Iterator` with position. This is more succinctly expressed by calling `any()`.
72-
--> $DIR/methods.rs:161:13
66+
--> $DIR/methods.rs:158:13
7367
|
7468
LL | let _ = v.iter().position(|&x| {
7569
| _____________^
@@ -79,13 +73,13 @@ LL | | ).is_some();
7973
| |______________________________^
8074

8175
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
82-
--> $DIR/methods.rs:167:22
76+
--> $DIR/methods.rs:164:22
8377
|
8478
LL | let _ = v.iter().rposition(|&x| x < 0).is_some();
8579
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `any(|&x| x < 0)`
8680

8781
error: called `is_some()` after searching an `Iterator` with rposition. This is more succinctly expressed by calling `any()`.
88-
--> $DIR/methods.rs:170:13
82+
--> $DIR/methods.rs:167:13
8983
|
9084
LL | let _ = v.iter().rposition(|&x| {
9185
| _____________^
@@ -94,5 +88,5 @@ LL | | }
9488
LL | | ).is_some();
9589
| |______________________________^
9690

97-
error: aborting due to 12 previous errors
91+
error: aborting due to 11 previous errors
9892

tests/ui/methods_fixable.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
3+
#![warn(clippy::filter_next)]
4+
5+
/// Checks implementation of `FILTER_NEXT` lint.
6+
fn main() {
7+
let v = vec![3, 2, 1, 0, -1, -2, -3];
8+
9+
// Single-line case.
10+
let _ = v.iter().find(|&x| *x < 0);
11+
}

tests/ui/methods_fixable.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// run-rustfix
2+
3+
#![warn(clippy::filter_next)]
4+
5+
/// Checks implementation of `FILTER_NEXT` lint.
6+
fn main() {
7+
let v = vec![3, 2, 1, 0, -1, -2, -3];
8+
9+
// Single-line case.
10+
let _ = v.iter().filter(|&x| *x < 0).next();
11+
}

tests/ui/methods_fixable.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead.
2+
--> $DIR/methods_fixable.rs:10:13
3+
|
4+
LL | let _ = v.iter().filter(|&x| *x < 0).next();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `v.iter().find(|&x| *x < 0)`
6+
|
7+
= note: `-D clippy::filter-next` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)