Clippy lints / Correctness
Clippy lint · Correctness · checked with Clippy 0.1.99
clippy::impossible_comparisons: Checks for double comparisons that can never succeed
What it meansChecks for double comparisons that can never succeed It is in the correctness group and denied by default (the build fails).
Does it matter?
The whole expression can be replaced by false, which is probably not the programmer’s intention
Code that is almost certainly wrong. Denied by default: the build fails until you fix it or allow it.
How to fix it
Clippy does not fix this one automatically. Change the code by hand:
Flagged
if status_code <= 400 && status_code > 500 {}
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::impossible_comparisons)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
impossible_comparisons = "allow"One run
cargo clippy -- -A clippy::impossible-comparisonsThe [lints] table needs Rust 1.74 or newer. In a workspace, put it under [workspace.lints.clippy] and add [lints] workspace = true to each member.
Clippy's own documentation
What it does
Checks for double comparisons that can never succeed
Why is this bad?
The whole expression can be replaced by false,
which is probably not the programmer’s intention
Example
if status_code <= 400 && status_code > 500 {}
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- if_let_mutexChecks for Mutex::lock calls in if let expression with lock calls in any of the else blocks
- ifs_same_condChecks for consecutive ifs with the same condition
- impl_hash_borrow_with_str_and_bytesthe semantics of `Borrow<T>` around `Hash` can't be satisfied when both `Borrow<str>` and `Borrow<[u8]>` are implemented
- ineffective_bit_maskChecks for bit masks in comparisons which can be removed without changing the outcome
- infinite_iterinfinite iteration detected
- inherent_to_string_shadow_displaytype `main::A` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::if_let_mutexChecks for Mutex::lock calls in if let expression with lock calls in any of the else blocksRead it next →Did this answer your question?