Description
The comparison_chain
lint is defined as:
Checks comparison chains written with if that can be rewritten with match and cmp.
However it also triggers on comparison chains written with if who's compared type does not implement Ord
and doesn't offer cmp
.
One such example would be f64
. This type implements PartialOrd
but not Ord
. It provides <
and >
operators without providing cmp
.
While in theory the same concept of using match
could also be applied to the result of partial_cmp
, I personally find matching over Optional<Ordering>
much less appealing than matching over Ordering
.
Should we apply the same lint to all PartialOrd
cases and change the documentation to make this the official desired behavior? Or should we consider this a bug and change the implementation, so that the lint only fires if cmp
is available on the relevant type (as specified in the documentation)?
cc @james9909
Example implementation where clippy::comparison_chain
fires, eventough cmp
is not available:
fn f(x: f64, y: f64) {
if x > y {
a()
} else if x < y {
b()
} else {
c()
}
}
Reproduced on:
clippy 0.0.212 (3aea860 2019-09-03)
clippy 0.0.212 (4e7e71b 2019-10-11)