rust-clippy
rust-clippy copied to clipboard
False positive in `map_identity` with lifetimes
Summary
Mapping with an identity closure (|x| x
) is sometimes required to fix lifetimes.
Lint Name
map_identity
Reproducer
I tried this code:
pub fn test<'a, I>(iter: I)
where
I: IntoIterator<Item = &'a i32>
{
let local = 0;
let _ = std::iter::once(&local).chain(iter.into_iter().map(|x| x));
}
Removing the map
results in a compile error.
I saw this happen:
warning: unnecessary map of the identity function
--> src/lib.rs:6:59
|
6 | let _ = std::iter::once(&local).chain(iter.into_iter().map(|x| x));
| ^^^^^^^^^^^ help: remove the call to `map`
|
= note: `#[warn(clippy::map_identity)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_identity
I expected to see this happen:
No warning, as the map
cannot be removed without causing a compile error. This happens on both stable and nightly.
Version
rustc 1.64.0-nightly (0f4bcadb4 2022-07-30)
binary: rustc
commit-hash: 0f4bcadb46006bc484dad85616b484f93879ca4e
commit-date: 2022-07-30
host: x86_64-pc-windows-msvc
release: 1.64.0-nightly
LLVM version: 14.0.6
Additional Labels
@rustbot label +I-suggestion-causes-error