Skip to content

Add real suggestion to option_map_unwrap_or #2320

Closed
@killercup

Description

@killercup

I'm not saying this is a lint I'd enable—but I just came across the fact that it currently generates outpt like this:

error: called `map(f).unwrap_or(a)` on an Option value. This can be done more directly by calling `map_or(a, f)` instead
   --> $DIR/methods.rs:103:13
    |
103 |       let _ = opt.map(|x| x + 1)
    |  _____________^
104 | |
105 | |                .unwrap_or(0); // should lint even though this call is on a separate line
    | |____________________________^
    |
    = note: `-D option-map-unwrap-or` implied by `-D warnings`
    = note: replace `map(|x| x + 1).unwrap_or(0)` with `map_or(0, |x| x + 1)`

It looks like the suggestion is pretty stable, right? Let's turn it into an actual rustfix-able suggestion, then!

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