Skip to content

Commit

Permalink
Extract might_have_negative_value() function
Browse files Browse the repository at this point in the history
  • Loading branch information
mgr-inz-rafal authored and flip1995 committed Dec 22, 2019
1 parent 9edbb78 commit 43c398f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clippy_lints/src/modulo_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ fn is_negative<'a, 'tcx>(c: &ptr::P<rustc::hir::Expr>, 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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 43c398f

Please sign in to comment.