forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 6 commits.
# This is the 1st commit message: Split filter_map into manual_filter_map # The commit message rust-lang#2 will be skipped: # fixup! Split filter_map into manual_filter_map # The commit message rust-lang#3 will be skipped: # fixup! Split filter_map into manual_filter_map # The commit message rust-lang#4 will be skipped: # fixup! Split filter_map into manual_filter_map # The commit message rust-lang#5 will be skipped: # fixup! Split filter_map into manual_filter_map # The commit message rust-lang#6 will be skipped: # fixup! Split filter_map into manual_filter_map
- Loading branch information
1 parent
d93889a
commit aaf6bcf
Showing
8 changed files
with
225 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
#![warn(clippy::manual_filter_map)] | ||
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure | ||
|
||
use std::iter; | ||
|
||
fn main() { | ||
// is_some(), unwrap() | ||
let _ = iter::once(1).filter_map(|a| to_opt(a)); | ||
|
||
// ref pattern, expect() | ||
let _ = iter::once(1).filter_map(|a| to_opt(a)); | ||
|
||
// is_ok(), unwrap_or() | ||
let _ = iter::once(1).filter_map(|a| to_res(a).ok()); | ||
} | ||
|
||
fn no_lint() { | ||
// no shared code | ||
let _ = iter::once(1).filter(|n| *n > 1).map(|n| n + 1); | ||
|
||
// very close but different since filter() provides a reference | ||
let _ = iter::once(1) | ||
.filter(|n| to_opt(n).is_some()) | ||
.map(|a| to_opt(a).unwrap()); | ||
|
||
// similar but different | ||
let _ = iter::once(1) | ||
.filter(|n| to_opt(n).is_some()) | ||
.map(|n| to_res(n).unwrap()); | ||
let _ = iter::once(1) | ||
.filter(|n| to_opt(n).map(|n| n + 1).is_some()) | ||
.map(|a| to_opt(a).unwrap()); | ||
} | ||
|
||
fn to_opt<T>(_: T) -> Option<T> { | ||
unimplemented!() | ||
} | ||
|
||
fn to_res<T>(_: T) -> Result<T, ()> { | ||
unimplemented!() | ||
} |
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,49 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
#![warn(clippy::manual_filter_map)] | ||
#![allow(clippy::redundant_closure)] // FIXME suggestion may have redundant closure | ||
|
||
use std::iter; | ||
|
||
fn main() { | ||
// is_some(), unwrap() | ||
let _ = iter::once(1) | ||
.filter(|n| to_opt(*n).is_some()) | ||
.map(|a| to_opt(a).unwrap()); | ||
|
||
// ref pattern, expect() | ||
let _ = iter::once(1) | ||
.filter(|&n| to_opt(n).is_some()) | ||
.map(|a| to_opt(a).expect("hi")); | ||
|
||
// is_ok(), unwrap_or() | ||
let _ = iter::once(1) | ||
.filter(|&n| to_res(n).is_ok()) | ||
.map(|a| to_res(a).unwrap_or(1)); | ||
} | ||
|
||
fn no_lint() { | ||
// no shared code | ||
let _ = iter::once(1).filter(|n| *n > 1).map(|n| n + 1); | ||
|
||
// very close but different since filter() provides a reference | ||
let _ = iter::once(1) | ||
.filter(|n| to_opt(n).is_some()) | ||
.map(|a| to_opt(a).unwrap()); | ||
|
||
// similar but different | ||
let _ = iter::once(1) | ||
.filter(|n| to_opt(n).is_some()) | ||
.map(|n| to_res(n).unwrap()); | ||
let _ = iter::once(1) | ||
.filter(|n| to_opt(n).map(|n| n + 1).is_some()) | ||
.map(|a| to_opt(a).unwrap()); | ||
} | ||
|
||
fn to_opt<T>(_: T) -> Option<T> { | ||
unimplemented!() | ||
} | ||
|
||
fn to_res<T>(_: T) -> Result<T, ()> { | ||
unimplemented!() | ||
} |
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,31 @@ | ||
error: `filter(..).map(..)` can be simplified as `filter_map(..)` | ||
--> $DIR/manual_filter_map.rs:10:26 | ||
| | ||
LL | let _ = iter::once(1) | ||
| __________________________^ | ||
LL | | .filter(|n| to_opt(*n).is_some()) | ||
LL | | .map(|a| to_opt(a).unwrap()); | ||
| |____________________________________^ help: try: `.filter_map(|a| to_opt(a))` | ||
| | ||
= note: `-D clippy::manual-filter-map` implied by `-D warnings` | ||
|
||
error: `filter(..).map(..)` can be simplified as `filter_map(..)` | ||
--> $DIR/manual_filter_map.rs:15:26 | ||
| | ||
LL | let _ = iter::once(1) | ||
| __________________________^ | ||
LL | | .filter(|&n| to_opt(n).is_some()) | ||
LL | | .map(|a| to_opt(a).expect("hi")); | ||
| |________________________________________^ help: try: `.filter_map(|a| to_opt(a))` | ||
|
||
error: `filter(..).map(..)` can be simplified as `filter_map(..)` | ||
--> $DIR/manual_filter_map.rs:20:26 | ||
| | ||
LL | let _ = iter::once(1) | ||
| __________________________^ | ||
LL | | .filter(|&n| to_res(n).is_ok()) | ||
LL | | .map(|a| to_res(a).unwrap_or(1)); | ||
| |________________________________________^ help: try: `.filter_map(|a| to_res(a).ok())` | ||
|
||
error: aborting due to 3 previous errors | ||
|