forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#8489 - smoelius:unnecessary-find-map, r=llogiq
Add `unnecessary_find_map` lint This PR adds an `unnecessary_find_map` lint. It is essentially just a minor enhancement of `unnecessary_filter_map`. Closes rust-lang#8467 changelog: New lint `unnecessary_find_map`
- Loading branch information
Showing
8 changed files
with
124 additions
and
17 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
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
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,23 @@ | ||
#![allow(dead_code)] | ||
|
||
fn main() { | ||
let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); | ||
let _ = (0..4).find_map(|x| { | ||
if x > 1 { | ||
return Some(x); | ||
}; | ||
None | ||
}); | ||
let _ = (0..4).find_map(|x| match x { | ||
0 | 1 => None, | ||
_ => Some(x), | ||
}); | ||
|
||
let _ = (0..4).find_map(|x| Some(x + 1)); | ||
|
||
let _ = (0..4).find_map(i32::checked_abs); | ||
} | ||
|
||
fn find_map_none_changes_item_type() -> Option<bool> { | ||
"".chars().find_map(|_| None) | ||
} |
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,38 @@ | ||
error: this `.find_map` can be written more simply using `.find` | ||
--> $DIR/unnecessary_find_map.rs:4:13 | ||
| | ||
LL | let _ = (0..4).find_map(|x| if x > 1 { Some(x) } else { None }); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::unnecessary-find-map` implied by `-D warnings` | ||
|
||
error: this `.find_map` can be written more simply using `.find` | ||
--> $DIR/unnecessary_find_map.rs:5:13 | ||
| | ||
LL | let _ = (0..4).find_map(|x| { | ||
| _____________^ | ||
LL | | if x > 1 { | ||
LL | | return Some(x); | ||
LL | | }; | ||
LL | | None | ||
LL | | }); | ||
| |______^ | ||
|
||
error: this `.find_map` can be written more simply using `.find` | ||
--> $DIR/unnecessary_find_map.rs:11:13 | ||
| | ||
LL | let _ = (0..4).find_map(|x| match x { | ||
| _____________^ | ||
LL | | 0 | 1 => None, | ||
LL | | _ => Some(x), | ||
LL | | }); | ||
| |______^ | ||
|
||
error: this `.find_map` can be written more simply using `.map(..).next()` | ||
--> $DIR/unnecessary_find_map.rs:16:13 | ||
| | ||
LL | let _ = (0..4).find_map(|x| Some(x + 1)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|