Skip to content

Commit

Permalink
Auto merge of rust-lang#3677 - daxpedda:integer_arithmetic, r=oli-obk
Browse files Browse the repository at this point in the history
Remove negative integer literal checks.

Fixes rust-lang#3678.
  • Loading branch information
bors committed Jan 21, 2019
2 parents e0bcec7 + 87d24e1 commit 9d5b148
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::consts::constant_simple;
use crate::utils::span_lint;
use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
Expand Down Expand Up @@ -94,8 +95,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Arithmetic {
hir::ExprKind::Unary(hir::UnOp::UnNeg, arg) => {
let ty = cx.tables.expr_ty(arg);
if ty.is_integral() {
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
self.expr_span = Some(expr.span);
if constant_simple(cx, cx.tables, expr).is_none() {
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
self.expr_span = Some(expr.span);
}
} else if ty.is_floating_point() {
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
self.expr_span = Some(expr.span);
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ fn main() {
i - 2 + 2 - i;
-i;

// no error, overflows are checked by `overflowing_literals`
-1;
-(-1);

i & 1; // no wrapping
i | 1;
i ^ 1;
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/arithmetic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,39 @@ LL | -i;
| ^^

error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:28:5
--> $DIR/arithmetic.rs:32:5
|
LL | f * 2.0;
| ^^^^^^^
|
= note: `-D clippy::float-arithmetic` implied by `-D warnings`

error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:30:5
--> $DIR/arithmetic.rs:34:5
|
LL | 1.0 + f;
| ^^^^^^^

error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:31:5
--> $DIR/arithmetic.rs:35:5
|
LL | f * 2.0;
| ^^^^^^^

error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:32:5
--> $DIR/arithmetic.rs:36:5
|
LL | f / 2.0;
| ^^^^^^^

error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:33:5
--> $DIR/arithmetic.rs:37:5
|
LL | f - 2.0 * 4.2;
| ^^^^^^^^^^^^^

error: floating-point arithmetic detected
--> $DIR/arithmetic.rs:34:5
--> $DIR/arithmetic.rs:38:5
|
LL | -f;
| ^^
Expand Down

0 comments on commit 9d5b148

Please sign in to comment.