Skip to content

Warn about using bool::then_some followed by unwrap_or, suggest if/else instead #9100

Open
@joshtriplett

Description

@joshtriplett

What it does

Detects the combination of then_some followed by unwrap_or in place of a more clear if/else.

Lint Name

bool_if_else

Category

style

Advantage

  • Clarity at a glance

Drawbacks

No response

Example

let mode = executable.then_some(IsExecutable).unwrap_or(IsNotExecutable);

Could be written as:

let mode = if executable { IsExecutable } else { IsNotExecutable };

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