-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integer_arithmetic: detect integer arithmetic on references.
Also fixes the same for float_arithmetic. changelog: integer_arithmetic,float_arithmetic: fix false negatives with references on integers Fixes #5328
- Loading branch information
1 parent
23549a8
commit c7c7ab2
Showing
3 changed files
with
162 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,211 @@ | ||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:13:5 | ||
--> $DIR/arithmetic.rs:15:5 | ||
| | ||
LL | 1 + i; | ||
| ^^^^^ | ||
| | ||
= note: `-D clippy::integer-arithmetic` implied by `-D warnings` | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:14:5 | ||
--> $DIR/arithmetic.rs:16:5 | ||
| | ||
LL | i * 2; | ||
| ^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:15:5 | ||
--> $DIR/arithmetic.rs:17:5 | ||
| | ||
LL | / 1 % | ||
LL | | i / 2; // no error, this is part of the expression in the preceding line | ||
| |_________^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:17:5 | ||
--> $DIR/arithmetic.rs:19:5 | ||
| | ||
LL | i - 2 + 2 - i; | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:18:5 | ||
--> $DIR/arithmetic.rs:20:5 | ||
| | ||
LL | -i; | ||
| ^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:30:5 | ||
--> $DIR/arithmetic.rs:32:5 | ||
| | ||
LL | i += 1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:31:5 | ||
--> $DIR/arithmetic.rs:33:5 | ||
| | ||
LL | i -= 1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:32:5 | ||
--> $DIR/arithmetic.rs:34:5 | ||
| | ||
LL | i *= 2; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:33:5 | ||
--> $DIR/arithmetic.rs:35:5 | ||
| | ||
LL | i /= 2; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:34:5 | ||
--> $DIR/arithmetic.rs:36:5 | ||
| | ||
LL | i %= 2; | ||
| ^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:45:5 | ||
--> $DIR/arithmetic.rs:47:5 | ||
| | ||
LL | f * 2.0; | ||
| ^^^^^^^ | ||
| | ||
= note: `-D clippy::float-arithmetic` implied by `-D warnings` | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:47:5 | ||
--> $DIR/arithmetic.rs:49:5 | ||
| | ||
LL | 1.0 + f; | ||
| ^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:48:5 | ||
--> $DIR/arithmetic.rs:50:5 | ||
| | ||
LL | f * 2.0; | ||
| ^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:49:5 | ||
--> $DIR/arithmetic.rs:51:5 | ||
| | ||
LL | f / 2.0; | ||
| ^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:50:5 | ||
--> $DIR/arithmetic.rs:52:5 | ||
| | ||
LL | f - 2.0 * 4.2; | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:51:5 | ||
--> $DIR/arithmetic.rs:53:5 | ||
| | ||
LL | -f; | ||
| ^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:53:5 | ||
--> $DIR/arithmetic.rs:55:5 | ||
| | ||
LL | f += 1.0; | ||
| ^^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:54:5 | ||
--> $DIR/arithmetic.rs:56:5 | ||
| | ||
LL | f -= 1.0; | ||
| ^^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:55:5 | ||
--> $DIR/arithmetic.rs:57:5 | ||
| | ||
LL | f *= 2.0; | ||
| ^^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:56:5 | ||
--> $DIR/arithmetic.rs:58:5 | ||
| | ||
LL | f /= 2.0; | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to 20 previous errors | ||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:101:5 | ||
| | ||
LL | 3 + &1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:102:5 | ||
| | ||
LL | &3 + 1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:103:5 | ||
| | ||
LL | &3 + &1; | ||
| ^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:108:5 | ||
| | ||
LL | a + x | ||
| ^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:112:5 | ||
| | ||
LL | x + y | ||
| ^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:116:5 | ||
| | ||
LL | x + y | ||
| ^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/arithmetic.rs:120:5 | ||
| | ||
LL | (&x + &y) | ||
| ^^^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:126:5 | ||
| | ||
LL | 3.1_f32 + &1.2_f32; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:127:5 | ||
| | ||
LL | &3.4_f32 + 1.5_f32; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:128:5 | ||
| | ||
LL | &3.5_f32 + &1.3_f32; | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:133:5 | ||
| | ||
LL | a + f | ||
| ^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:137:5 | ||
| | ||
LL | f1 + f2 | ||
| ^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:141:5 | ||
| | ||
LL | f1 + f2 | ||
| ^^^^^^^ | ||
|
||
error: floating-point arithmetic detected | ||
--> $DIR/arithmetic.rs:145:5 | ||
| | ||
LL | (&f1 + &f2) | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to 34 previous errors | ||
|