Skip to content

Lint if lets that could be better worded as equality #1716

Closed
@clarfonthey

Description

@clarfonthey

This would also affect the single_match lint. Essentially, whenever someone writes a pattern like this:

if let Ordering::Greater = a.cmp(b) { ... }

It would be a bit clearer to write something like this:

if a.cmp(b) == Ordering::Greater { ... }

Specifically, if the left hand side of the if let contains a value that can be constructed directly, and the destructured value implements PartialEq, then is makes a lot more sense to refactor the if let into a direct comparison.

This would also affect the single_match and single_match_else lints to give proper suggestions, i.e. changing:

match a.cmp(b) {
    Ordering::Greater => { ... },
    _ => {},
}

to:

if a.cmp(b) == Ordering::Greater { ... }

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