-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Lint name: unnecessary_filter_map
I tried this code:
fn test() -> impl Iterator<Item = u64> {
vec![()].into_iter().filter_map(|_| None)
}
I expected to see this happen:
The filter map is required because the Item
is being changed from ()
to u64
, so I expected this to not be linted.
Instead, this happened:
The code is linted as failing unnecessary_filter_map
, despite the use of filter_map
being required:
warning: this `.filter_map` can be written more simply using `.filter`
But filter
does not compile because that does not do the necessary type conversion for Item
:
fn test() -> impl Iterator<Item = u64> {
vec![()].into_iter().filter(|_| false)
}
error[E0271]: type mismatch resolving `<std::iter::Filter<std::vec::IntoIter<()>, [closure@<location>]> as Iterator>::Item == u64`
--> <location>
|
7 | fn test() -> impl Iterator<Item = u64> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `u64`
Meta
cargo clippy -V
:clippy 0.0.212 (cb75ad5 2021-02-10)
rustc -Vv
:rustc 1.50.0 (cb75ad5db 2021-02-10) binary: rustc commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b commit-date: 2021-02-10 host: x86_64-unknown-linux-gnu release: 1.50.0
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.I-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have