-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move fixable
filter_next
and filter_map_next
cases to rustfixed t…
…ests
- Loading branch information
Showing
10 changed files
with
79 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|