Skip to content

x if x == <float literal> is marked as "redundant guard" #11304

@its-the-shrimp

Description

@its-the-shrimp

Summary

In spite of rustc considering floating point literals a deprecated match pattern, clippy emits a "redundant guard" warning for x if x == <float literal> and instead suggests replacing that with the literal itself.

Lint Name

redundant_guards

Reproducer

I tried this code:

fn main() {
    match 0.1 {
        x if x == 0.0 => todo!(),
        _ => todo!()
    }
}

I saw this happen:

warning: redundant guard
 --> test.rs:3:14
  |
3 |         x if x == 0.0 => todo!(),
  |              ^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_guards
  = note: `#[warn(clippy::redundant_guards)]` on by default
help: try
  |
3 -         x if x == 0.0 => todo!(),
3 +         0.0 => todo!(),
  |

warning: 1 warning emitted

I expected to see this happen:
no warnings from clippy

Version

rustc 1.73.0-nightly (03a119b0b 2023-08-07)
binary: rustc
commit-hash: 03a119b0b0e310d22d94399b24ed030056050f13
commit-date: 2023-08-07
host: aarch64-apple-darwin
release: 1.73.0-nightly
LLVM version: 16.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions