Skip to content

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

Open

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 };

Activity

  1. joshtriplett commented on Jul 2, 2022

    @joshtriplett
    MemberAuthor

    This should also apply with any combination of then/then_some and unwrap_or/unwrap_or_else.

  2. arieluy commented on Jul 10, 2022

    @arieluy
    Contributor

    @rustbot claim

  3. added a commit that references this issue on Jul 18, 2022
  4. arieluy commented on Jul 28, 2022

    @arieluy
    Contributor

    My commit adds the lint for then_some/unwrap_or, more commits needed to address other cases. I'll get to them at some point, but anyone can feel free to take them before me.

  5. removed their assignment
    on Nov 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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