`filter_map_identity` is arguably overzealous
Description
lint: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity
This was originally added as being like flat_map_identity (https://github.com/rust-lang/rust-clippy/pull/6685), but they're not quite analogous. .flatten() is unambiguously better than .flat_map(identity), but the same isn't true for .filter_map(identity).
The problem is that (as I recently mentioned in https://github.com/rust-lang/rust/pull/99230#discussion_r955364588), FlatMap (including Flatten) is a fundamentally harder problem than FilterMap, because it needs to deal in iterators that might have more than one item. And thus, for example,
let flatten_it = a.iter().copied().flatten();
let filter_map_it = a.iter().copied().filter_map(|x| x);
dbg!([size_of_val(&flatten_it), size_of_val(&filter_map_it)]); // 32, 16
dbg!([flatten_it.size_hint(), filter_map_it.size_hint()]); // (0, None), (0, Some(3))
So perhaps this shouldn't be warn-by-default when it would also be plausible to have a performance-category lint to say to do exactly the opposite.
Version
(Not really version-specific; inherent to the definition of the lint.)
Additional Labels
@rustbot label +I-false-positive
FWIW, nightly flatten now fares a little better in that example. The size_of difference is still there, but it uses a specialized implementation, including a size hint as good as filter_map's.