Skip to content

Commit 7be3e11

Browse files
committed
Refactor binary operation node pattern matching code to improve readability.
Also handle cases where the if-statement's condition is not a `DropTemps` expression.
1 parent 5c2e5ab commit 7be3e11

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

clippy_lints/src/collapsible_if.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,10 @@ fn check_collapsible_if_nested_if_else(cx: &LateContext<'_>, if_expr: &Expr<'_>)
9999
ExprKind::Binary(bin_op, lhs, rhs) => {
100100
let new_bin_op;
101101

102-
match bin_op.node {
103-
BinOpKind::Ne => {
104-
new_bin_op = BinOpKind::Eq;
105-
},
106-
_ => {
107-
new_bin_op = BinOpKind::Ne;
108-
},
102+
if let BinOpKind::Ne = bin_op.node {
103+
new_bin_op = BinOpKind::Eq;
104+
} else {
105+
new_bin_op = BinOpKind::Ne;
109106
}
110107

111108
cond_sugg =
@@ -121,6 +118,8 @@ fn check_collapsible_if_nested_if_else(cx: &LateContext<'_>, if_expr: &Expr<'_>)
121118
},
122119
_ => {},
123120
}
121+
} else {
122+
cond_sugg = make_unop("!", Sugg::hir(cx, cond, ".."));
124123
}
125124

126125
span_lint_and_then(

0 commit comments

Comments
 (0)