Open
Description
Summary
While it's technically not an identity function, |&x| x
and ||x| x.as_ref()|
should be linted for the same reasons as |x| x
Lint Name
clippy::filter_map_identity
Reproducer
I tried this code:
struct NonCopy;
fn main() {
_ = vec![Some(()), None, Some(())].iter().filter_map(|&x| x);
_ = vec![Some(NonCopy), None, Some(NonCopy)].iter().filter_map(|x| x.as_ref());
_ = vec![Some(()), None, Some(())].iter_mut().filter_map(|&mut x| x);
_ = vec![Some(NonCopy), None, Some(NonCopy)].iter_mut().filter_map(|x| x.as_mut());
}
I expected to see this happen: 4 warnings
Instead, this happened: clippy is silent
Version
cargo 1.78.0-nightly (2fe739fcf 2024-03-15)
release: 1.78.0-nightly
commit-hash: 2fe739fcf16c5bf8c2064ab9d357f4a0e6c8539b
commit-date: 2024-03-15
host: x86_64-pc-windows-msvc
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:Schannel)
os: Windows 10.0.19045 (Windows 10 Home) [64-bit]