Closed
Description
This code
fn bla(a: i32, b: i32) {
if a > b {
} else if a < b {
}
}
Triggers clippy::comparison_chain
:
warning: `if` chain can be rewritten with `match`
--> src/lib.rs:2:5
|
2 | / if a > b {
3 | | } else if a < b {
4 | | }
| |_____^
|
= note: `#[warn(clippy::comparison_chain)]` on by default
= help: Consider rewriting the `if` chain to use `cmp` and `match`.
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain
however using a match forces us to cover one additional case which the if-construct does not have: Ordering::Equal
is not covered originally and we would have to use something like
_ => {}
to get our code to compile.
Perhaps the lint should be refactored to only warn if there is also a final else
/if there are 3 cases that are handled by the if-condition construct?
clippy 0.0.212 (e8d5a9e 2019-10-22)