Skip to content

Lint: useless/unidiomatic match statement on bool #8014

@codybloemhard

Description

@codybloemhard

What it does

Catch code that flips a boolean with a match statement, as well as code that applies the identity function over a boolean with a match statement.
Lints for code like this exists:

let a = true;
let b = if a { false } else { true };
let c = if b == true { false } else { true };
let d = if c { true } else { false };

but there seems to be no lint for code like this:

let a = true;
let b = match a{
    true => false,
    false => true,
};

I saw someone writing that piece of code, so it could be useful if there was a lint for it.

Categories (optional)

  • clippy::style

What is the advantage of the recommended code over the original code

  • The recommended is code is shorter and more readable.

Drawbacks

None.

Example 0

let a = true;
let b = match a{
    true => false,
    false => true,
};

Could be written as:

let a = true;
let b = !a;

Example 1

let a = true;
let b = match a{
    true => true,
    false => false,
};

Could be written as:

let a = true;
let b = a;

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesS-fixedStatus: Issues that got fixed, waiting to be closed as completed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions