Skip to content

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

Closed

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 { ... }

Activity

  1. added 2 commits that reference this issue on Oct 4, 2021
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