Skip to content

Commit e330bc3

Browse files
committed
clippy_dogfood
1 parent 68ce04f commit e330bc3

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

clippy_lints/src/casts/cast_sign_loss.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -222,32 +222,29 @@ fn exprs_with_muldiv_binop_peeled<'e>(expr: &'e Expr<'_>) -> Vec<&'e Expr<'e>> {
222222
let mut res = vec![];
223223

224224
for_each_expr(expr, |sub_expr| {
225-
match sub_expr.kind {
226-
ExprKind::Binary(op, lhs, _rhs) => {
227-
if matches!(op.node, BinOpKind::Mul | BinOpKind::Div) {
228-
// For binary operators which both contribute to the sign of the result,
229-
// collect all their operands, recursively. This ignores overflow.
230-
ControlFlow::Continue(Descend::Yes)
231-
} else if matches!(op.node, BinOpKind::Rem) {
232-
// For binary operators where the left hand side determines the sign of the result,
233-
// only collect that side, recursively. Overflow panics, so this always holds.
234-
//
235-
// > Given remainder = dividend % divisor, the remainder will have the same sign as the dividend
236-
// https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators
237-
res.push(lhs);
238-
ControlFlow::Break(())
239-
} else {
240-
// The sign of the result of other binary operators depends on the values of the operands,
241-
// so try to evaluate the expression.
242-
res.push(expr);
243-
ControlFlow::Continue(Descend::No)
244-
}
245-
},
246-
// For other expressions, including unary operators and constants, try to evaluate the expression.
247-
_ => {
225+
if let ExprKind::Binary(op, lhs, _rhs) = sub_expr.kind {
226+
if matches!(op.node, BinOpKind::Mul | BinOpKind::Div) {
227+
// For binary operators which both contribute to the sign of the result,
228+
// collect all their operands, recursively. This ignores overflow.
229+
ControlFlow::Continue(Descend::Yes)
230+
} else if matches!(op.node, BinOpKind::Rem) {
231+
// For binary operators where the left hand side determines the sign of the result,
232+
// only collect that side, recursively. Overflow panics, so this always holds.
233+
//
234+
// > Given remainder = dividend % divisor, the remainder will have the same sign as the dividend
235+
// https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators
236+
res.push(lhs);
237+
ControlFlow::Break(())
238+
} else {
239+
// The sign of the result of other binary operators depends on the values of the operands,
240+
// so try to evaluate the expression.
248241
res.push(expr);
249242
ControlFlow::Continue(Descend::No)
250-
},
243+
}
244+
} else {
245+
// For other expressions, including unary operators and constants, try to evaluate the expression.
246+
res.push(expr);
247+
ControlFlow::Continue(Descend::No)
251248
}
252249
});
253250

0 commit comments

Comments
 (0)