clippy_dogfood

This commit is contained in:
teor 2024-01-16 19:00:32 +10:00
parent 740441fd98
commit 6dfff19090

View File

@ -222,32 +222,29 @@ fn exprs_with_muldiv_binop_peeled<'e>(expr: &'e Expr<'_>) -> Vec<&'e Expr<'e>> {
let mut res = vec![]; let mut res = vec![];
for_each_expr(expr, |sub_expr| { for_each_expr(expr, |sub_expr| {
match sub_expr.kind { if let ExprKind::Binary(op, lhs, _rhs) = sub_expr.kind {
ExprKind::Binary(op, lhs, _rhs) => { if matches!(op.node, BinOpKind::Mul | BinOpKind::Div) {
if matches!(op.node, BinOpKind::Mul | BinOpKind::Div) { // For binary operators which both contribute to the sign of the result,
// For binary operators which both contribute to the sign of the result, // collect all their operands, recursively. This ignores overflow.
// collect all their operands, recursively. This ignores overflow. ControlFlow::Continue(Descend::Yes)
ControlFlow::Continue(Descend::Yes) } else if matches!(op.node, BinOpKind::Rem) {
} else if matches!(op.node, BinOpKind::Rem) { // For binary operators where the left hand side determines the sign of the result,
// For binary operators where the left hand side determines the sign of the result, // only collect that side, recursively. Overflow panics, so this always holds.
// only collect that side, recursively. Overflow panics, so this always holds. //
// // > Given remainder = dividend % divisor, the remainder will have the same sign as the dividend
// > Given remainder = dividend % divisor, the remainder will have the same sign as the dividend // https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators
// https://doc.rust-lang.org/reference/expressions/operator-expr.html#arithmetic-and-logical-binary-operators res.push(lhs);
res.push(lhs); ControlFlow::Break(())
ControlFlow::Break(()) } else {
} else { // The sign of the result of other binary operators depends on the values of the operands,
// The sign of the result of other binary operators depends on the values of the operands, // so try to evaluate the expression.
// so try to evaluate the expression.
res.push(expr);
ControlFlow::Continue(Descend::No)
}
},
// For other expressions, including unary operators and constants, try to evaluate the expression.
_ => {
res.push(expr); res.push(expr);
ControlFlow::Continue(Descend::No) ControlFlow::Continue(Descend::No)
}, }
} else {
// For other expressions, including unary operators and constants, try to evaluate the expression.
res.push(expr);
ControlFlow::Continue(Descend::No)
} }
}); });