Skip to content

Replace map_or(false, ...) with is_some_and or is_ok_and #11848

Open
@ronnodas

Description

@ronnodas

What it does

The methods Option::is_some_and and Result::is_{ok,err}_and are designed to replace the common patterns map_or(false, ...) and map_err_or(false, ...). Potentially could also replace map_or(true, ...) with !is_some_and(!...). Probably should be a pedantic lint.

#9125 is similar but for map(...).unwrap_or(false).

Advantage

Expresses the intent better and is slightly more concise.

Drawbacks

No response

Example

Some(42).map_or(false, |value| value > 0)

Could be written as:

Some(42).is_some_and(|value| value > 0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions