Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
its-the-shrimp opened this issue Aug 8, 2023 · 0 comments · Fixed by #11305
Closed

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

its-the-shrimp opened this issue Aug 8, 2023 · 0 comments · Fixed by #11305
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@its-the-shrimp
Copy link
Contributor

its-the-shrimp commented Aug 8, 2023

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

@its-the-shrimp its-the-shrimp added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Aug 8, 2023
@bors bors closed this as completed in 7c595b4 Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant