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:
commit
fe5cefceba
9 changed files with 110 additions and 3 deletions
13
tests/ui/flat_map_option.fixed
Normal file
13
tests/ui/flat_map_option.fixed
Normal 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));
|
||||
}
|
||||
13
tests/ui/flat_map_option.rs
Normal file
13
tests/ui/flat_map_option.rs
Normal 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));
|
||||
}
|
||||
16
tests/ui/flat_map_option.stderr
Normal file
16
tests/ui/flat_map_option.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue