Summary
Code in the and_then closure will only run when the first option is Some. And manual_option_zip triggers when this code includes things like function calls, which would otherwise not be invoked.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=ee87d8154bd0d80e2a4348630d1da139
Lint Name
manual_option_zip
Reproducer
I tried this code:
pub fn test(a: Option<u8>, try_get_val: impl FnOnce() -> Option<u8>) -> Option<(u8, u8)> {
a.and_then(|a| try_get_val().map(|b| (a, b)))
}
I saw this happen:
warning: manual implementation of `Option::zip`
--> src/main.rs:2:5
|
2 | a.and_then(|a| try_get_val().map(|b| (a, b)))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `a.zip(try_get_val())`
|
= 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:
No lint
Version
1.98.0-nightly (2026-06-14 3daae5e42ec9ba435212)
Additional Labels
No response
Summary
Code in the
and_thenclosure will only run when the first option isSome. Andmanual_option_ziptriggers when this code includes things like function calls, which would otherwise not be invoked.https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=ee87d8154bd0d80e2a4348630d1da139
Lint Name
manual_option_zip
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No lint
Version
Additional Labels
No response