Auto merge of #7101 - camsteffen:flat-map-option, r=giraffate

Add flat_map_option lint

changelog: Add flat_map_option lint

Closes #2241
This commit is contained in:
bors 2021-04-19 13:34:23 +00:00
commit fe5cefceba
9 changed files with 110 additions and 3 deletions

View file

@ -0,0 +1,13 @@
// run-rustfix
#![warn(clippy::flat_map_option)]
#![allow(clippy::redundant_closure, clippy::unnecessary_filter_map)]
fn main() {
// yay
let c = |x| Some(x);
let _ = [1].iter().filter_map(c);
let _ = [1].iter().filter_map(Some);
// nay
let _ = [1].iter().flat_map(|_| &Some(1));
}

View file

@ -0,0 +1,13 @@
// run-rustfix
#![warn(clippy::flat_map_option)]
#![allow(clippy::redundant_closure, clippy::unnecessary_filter_map)]
fn main() {
// yay
let c = |x| Some(x);
let _ = [1].iter().flat_map(c);
let _ = [1].iter().flat_map(Some);
// nay
let _ = [1].iter().flat_map(|_| &Some(1));
}

View file

@ -0,0 +1,16 @@
error: used `flat_map` where `filter_map` could be used instead
--> $DIR/flat_map_option.rs:8:24
|
LL | let _ = [1].iter().flat_map(c);
| ^^^^^^^^ help: try: `filter_map`
|
= note: `-D clippy::flat-map-option` implied by `-D warnings`
error: used `flat_map` where `filter_map` could be used instead
--> $DIR/flat_map_option.rs:9:24
|
LL | let _ = [1].iter().flat_map(Some);
| ^^^^^^^^ help: try: `filter_map`
error: aborting due to 2 previous errors