Skip to content

Suggest Option::map_or(_else) for if let Some { y } else { x } #5203

Closed
@Luro02

Description

@Luro02

This code:

if let Some(v) = optional {
    v == &"hello"
} else {
    false
}

could be optimized to

optional.as_ref().map_or(false, |v| v == &"hello")

[playground]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-styleLint: Belongs in the style lint groupL-suggestionLint: Improving, adding or fixing lint suggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions