Skip to content

Commit 43c398f

Browse files
mgr-inz-rafalflip1995
authored andcommitted
Extract might_have_negative_value() function
1 parent 9edbb78 commit 43c398f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

clippy_lints/src/modulo_arithmetic.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ fn is_negative<'a, 'tcx>(c: &ptr::P<rustc::hir::Expr>, cx: &LateContext<'a, 'tcx
5151
None
5252
}
5353

54+
fn might_have_negative_value(t: &ty::TyS<'_>) -> bool {
55+
(t.is_integral() && t.is_signed()) || t.is_floating_point()
56+
}
57+
5458
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ModuloArithmetic {
5559
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
5660
match &expr.kind {
@@ -79,8 +83,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ModuloArithmetic {
7983
} else {
8084
// Operands are not consts, fallback to the 'might have different signs' lint
8185
let lhs_type = cx.tables.expr_ty(lhs);
82-
if (lhs_type.is_integral() && lhs_type.is_signed()) || lhs_type.is_floating_point() {
83-
// Extract method
86+
if might_have_negative_value(lhs_type) {
8487
span_help_and_lint(
8588
cx,
8689
MODULO_ARITHMETIC,

0 commit comments

Comments
 (0)