Skip to content

Commit

Permalink
removed lint for division/modulo for literal 0
Browse files Browse the repository at this point in the history
  • Loading branch information
henil committed Oct 30, 2020
1 parent e97602e commit fa0a78b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
7 changes: 1 addition & 6 deletions clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {
if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() {
match op.node {
hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind {
hir::ExprKind::Lit(lit) => {
if let rustc_ast::ast::LitKind::Int(0, _) = lit.node {
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
self.expr_span = Some(expr.span);
}
},
hir::ExprKind::Lit(_lit) => (),
hir::ExprKind::Unary(hir::UnOp::UnNeg, expr) => {
if let hir::ExprKind::Lit(lit) = &expr.kind {
if let rustc_ast::ast::LitKind::Int(1, _) = lit.node {
Expand Down
14 changes: 1 addition & 13 deletions tests/ui/integer_arithmetic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ error: integer arithmetic detected
LL | i *= 2;
| ^^^^^^

error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:37:5
|
LL | i /= 0;
| ^^^^^^

error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:38:11
|
Expand All @@ -99,12 +93,6 @@ error: integer arithmetic detected
LL | i /= var2;
| ^^^^^^^^^

error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:42:5
|
LL | i %= 0;
| ^^^^^^

error: integer arithmetic detected
--> $DIR/integer_arithmetic.rs:43:11
|
Expand Down Expand Up @@ -177,5 +165,5 @@ error: integer arithmetic detected
LL | (&x + &y)
| ^^^^^^^^^

error: aborting due to 29 previous errors
error: aborting due to 27 previous errors

0 comments on commit fa0a78b

Please sign in to comment.