Skip to content

The suggested code by option_map_or_none is warned again in some case #7960

@giraffate

Description

@giraffate
fn main() { let opt = Some(3); opt.map_or(None, |a| Some(a + 1)); }

Clippy warns like below on this:

 | 3 | opt.map_or(None, |a| Some(a + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(|a| Some(a + 1))` | 

So I updated it according to the warning:

fn main() { let opt = Some(3); opt.and_then(|a| Some(a + 1)); }

But, Clippy warns like below again:

 | 3 | opt.and_then(|a| Some(a + 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `opt.map(|a| a + 1)` | 

In this case, I want option_map_or_none to suggest the last code suggested from the beginning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions