-
Notifications
You must be signed in to change notification settings - Fork 2k
Lint when > or >= is used i.e. compared values are not listed in (number line) order #13082
Copy link
Copy link
Open
Labels
A-lintArea: New lintsArea: New lints
Description
What it does
Check that < and <= are used rather than > or >= so that compared values are listed in order.
Advantage
- unified style
- some find it easier to reason about (prompted by fix: Ensure dep/feature activates the dependency on 2024 cargo#14221 (comment))
Drawbacks
- Its rather opinionated so should probably be allow by default style/pedantic lint
- inversion might not be possible if only the
PartialEqimpl for one direction is implemented, so it might need to be limited to cases where the operands implementEq
Example
Could be written as:
if val >= min && max >= val {
// do something
}if min <= val && val <= max {
// do something
}Preferably it would also recognize common operands so that
if val <= max && min <= val {
// do something
}
if max <= val || val <= min {
// do something
}would become
if min <= val && val <= max {
// do something
}
if val <= min && max <= val {
// do something
}i.e. for && move common value to the operator and for || move common value away from the operator
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints
Type
Fields
Give feedbackNo fields configured for issues without a type.