Clippy lints / Complexity
Clippy lint · Complexity · checked with Clippy 0.1.99
clippy::double_comparisons: Checks for double comparisons that could be simplified to a single expression
What it meansChecks for double comparisons that could be simplified to a single expression. It is in the complexity group and warns by default.
Does it matter?
Readability.
Code that does something simple in a complicated way. Warns by default.
How to fix it
Clippy can fix this one for you: run cargo clippy --fix (add --allow-dirty if you have uncommitted changes). Review the diff before you commit.
Flagged
if x == y || x < y {}
Write this instead
if x <= y {}
Turn it off, or on
Allow it where it does not fit your code, as narrowly as you can:
On one item
#[allow(clippy::double_comparisons)]
fn my_function() { /* ... */ }Whole crate (Cargo.toml)
[lints.clippy]
double_comparisons = "allow"One run
cargo clippy -- -A clippy::double-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 could be simplified to a single expression.
Why is this bad?
Readability.
Example
if x == y || x < y {}
Use instead:
if x <= y {}
From the Clippy lint list (0.1.99), part of the Rust project, MIT or Apache-2.0. Official entry.
Related lints
- too_many_argumentsChecks for functions with too many parameters
- clone_on_copyusing `clone` on type `u64` which implements the `Copy` trait
- type_complexityChecks for types used in structs, parameters and let declarations above a certain complexity threshold
- deref_addrofChecks for usage of *& and *&mut in expressions
- derivable_implsthis `impl` can be derived
- diverging_sub_expressionChecks for diverging calls that are not match arms or statements
- double_parensunnecessary parentheses
- duration_subsecChecks for calculation of subsecond microseconds or milliseconds from other Duration methods
- excessive_nestingChecks for blocks which are nested beyond a certain threshold. Note: Even though this lint is warn-by-default, it will only trigger if a maximum nesting level is defined in the clippy.toml file
All 847 Clippy lints · Rust compiler errors · Cargo.toml checker
Up next
Related lintclippy::too_many_argumentsChecks for functions with too many parametersRead it next →Did this answer your question?