simplify matching on binop result
This commit is contained in:
parent
7696c9d1d5
commit
aca4086d7f
@ -229,21 +229,17 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
|
|||||||
|
|
||||||
ExprKind::Binary(op, left, right)
|
ExprKind::Binary(op, left, right)
|
||||||
if matches!(op.node, BinOpKind::Div | BinOpKind::Rem)
|
if matches!(op.node, BinOpKind::Div | BinOpKind::Rem)
|
||||||
&& let left_ty = self.cx.typeck_results().expr_ty(left)
|
|
||||||
&& let right_ty = self.cx.typeck_results().expr_ty(right)
|
&& let right_ty = self.cx.typeck_results().expr_ty(right)
|
||||||
&& let left = constant(self.cx, self.cx.typeck_results(), left)
|
&& let left = constant(self.cx, self.cx.typeck_results(), left)
|
||||||
.and_then(|c| c.int_value(self.cx, left_ty))
|
|
||||||
&& let right = constant(self.cx, self.cx.typeck_results(), right)
|
&& let right = constant(self.cx, self.cx.typeck_results(), right)
|
||||||
.and_then(|c| c.int_value(self.cx, right_ty))
|
.and_then(|c| c.int_value(self.cx, right_ty))
|
||||||
&& match (left, right) {
|
&& matches!(
|
||||||
// `1 / x` -- x might be zero
|
(left, right),
|
||||||
(_, None) => true,
|
// `1 / x`: x might be zero
|
||||||
// `x / -1` -- x might be T::MIN = panic
|
(_, None)
|
||||||
#[expect(clippy::match_same_arms)]
|
// `x / -1`: x might be T::MIN
|
||||||
(None, Some(FullInt::S(-1))) => true,
|
| (None, Some(FullInt::S(-1)))
|
||||||
// anything else is either fine or checked by the compiler
|
) =>
|
||||||
_ => false,
|
|
||||||
} =>
|
|
||||||
{
|
{
|
||||||
self.eagerness |= NoChange;
|
self.eagerness |= NoChange;
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user