Skip to content

Nit re unnnecessary_map_or message #13704

@smoelius

Description

@smoelius

I recently started getting suggestions to replace .map_or(false, ...) with is_ok_and(...)/is_some_and(...):

warning: this `map_or` is redundant
 --> src/main.rs:6:20
  |
6 |     println!("{}", c.map_or(false, char::is_alphabetic));
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use is_some_and instead: `c.is_some_and(char::is_alphabetic)`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or
  = note: `#[warn(clippy::unnecessary_map_or)]` on by default

I like the suggestions 🙏, but I'm not sure "is redundant" is the right phrase to use in the warning.

Maybe "can be simplified"?

Playground for those who haven't come across this yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions