Summary
When the captured parameter is used in the inner closure, this lint is not supposed to fire. However, when the captured parameter is only used in a closure, clippy appears not to see the usage, incorrectly triggering the lint.
Lint Name
manual_option_zip
Reproducer
I tried this code:
fn main() {
let a = Some(1);
// correctly does not fire:
let opts = [Some(1), Some(2)];
let _ = a.and_then(|a| opts[a as usize].map(|b| (a, b)));
// incorrectly fires:
let opts = [1, 2];
let _ = a.and_then(|a| opts.into_iter().find(|b| *b == a).map(|b| (a, b)));
}
I saw this happen:
warning: manual implementation of `Option::zip`
--> src/main.rs:6:13
|
6 | let _ = a.and_then(|a| opts.into_iter().find(|b| *b == a).map(|b| (a, b)));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `a.zip(opts.into_iter().find(|b| *b == a))`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_option_zip
= note: `#[warn(clippy::manual_option_zip)]` on by default
I expected to see this happen:
Version
rustc 1.97.0-nightly (cb40c25f6 2026-05-04)
binary: rustc
commit-hash: cb40c25f6aebb637163d26bf76a680ed6e5d1eda
commit-date: 2026-05-04
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4
Additional Labels
@rustbot label +I-suggestion-causes-error
Summary
When the captured parameter is used in the inner closure, this lint is not supposed to fire. However, when the captured parameter is only used in a closure, clippy appears not to see the usage, incorrectly triggering the lint.
Lint Name
manual_option_zip
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
Version
Additional Labels
@rustbot label +I-suggestion-causes-error