diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index 360db7edd88f..ec0ec25a6ccd 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -51,6 +51,10 @@ fn is_negative<'a, 'tcx>(c: &ptr::P, cx: &LateContext<'a, 'tcx None } +fn might_have_negative_value(t: &ty::TyS<'_>) -> bool { + (t.is_integral() && t.is_signed()) || t.is_floating_point() +} + impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ModuloArithmetic { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) { match &expr.kind { @@ -79,8 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ModuloArithmetic { } else { // Operands are not consts, fallback to the 'might have different signs' lint let lhs_type = cx.tables.expr_ty(lhs); - if (lhs_type.is_integral() && lhs_type.is_signed()) || lhs_type.is_floating_point() { - // Extract method + if might_have_negative_value(lhs_type) { span_help_and_lint( cx, MODULO_ARITHMETIC,