RS.CLIPPY.EQUATABLE_IF_LET

Using pattern matching instead of equality

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: equatable_if_let. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for pattern matchings that can be expressed using equality.

Why is this bad?

  • It reads better and has less cognitive load because equality won't cause binding.
  • It is a Yoda condition. Yoda conditions are widely criticized for increasing the cognitive load of reading the code.
  • Equality is a simple bool expression and can be merged with && and || and reuse if blocks

Example

if let Some(2) = x {
    do_thing();
}

Use instead:

if x == Some(2) {
    do_thing();
}