Skip to content

manual_option_zip suggests making conditional calls unconditional #17253

Description

@Imberflur

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions