forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#6229 - henil:improve-integer-division-lint, r…
…=phansch Update the existing arithmetic lint re: rust-lang#6209 Updates the lint to not the error message if RHS of binary operation `/` of `%` is a literal/constant that is not `0` or `-1`, as suggested [here](rust-lang/rust-clippy#6209 (comment)) changelog: Expand [`integer_arithmetic`] to work with RHS literals and constants
- Loading branch information
Showing
3 changed files
with
97 additions
and
30 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,131 +1,169 @@ | ||
error: this operation will panic at runtime | ||
--> $DIR/integer_arithmetic.rs:37:5 | ||
| | ||
LL | i /= 0; | ||
| ^^^^^^ attempt to divide `_` by zero | ||
| | ||
= note: `#[deny(unconditional_panic)]` on by default | ||
|
||
error: this operation will panic at runtime | ||
--> $DIR/integer_arithmetic.rs:42:5 | ||
| | ||
LL | i %= 0; | ||
| ^^^^^^ attempt to calculate the remainder of `_` with a divisor of zero | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:14:5 | ||
--> $DIR/integer_arithmetic.rs:16:5 | ||
| | ||
LL | 1 + i; | ||
| ^^^^^ | ||
| | ||
= note: `-D clippy::integer-arithmetic` implied by `-D warnings` | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:15:5 | ||
--> $DIR/integer_arithmetic.rs:17:5 | ||
| | ||
LL | i * 2; | ||
| ^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:16:5 | ||
--> $DIR/integer_arithmetic.rs:18:5 | ||
| | ||
LL | / 1 % | ||
LL | | i / 2; // no error, this is part of the expression in the preceding line | ||
| |_________^ | ||
| |_____^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:18:5 | ||
--> $DIR/integer_arithmetic.rs:20:5 | ||
| | ||
LL | i - 2 + 2 - i; | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:19:5 | ||
--> $DIR/integer_arithmetic.rs:21:5 | ||
| | ||
LL | -i; | ||
| ^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:20:5 | ||
--> $DIR/integer_arithmetic.rs:22:5 | ||
| | ||
LL | i >> 1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:21:5 | ||
--> $DIR/integer_arithmetic.rs:23:5 | ||
| | ||
LL | i << 1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:31:5 | ||
--> $DIR/integer_arithmetic.rs:33:5 | ||
| | ||
LL | i += 1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:32:5 | ||
--> $DIR/integer_arithmetic.rs:34:5 | ||
| | ||
LL | i -= 1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:33:5 | ||
--> $DIR/integer_arithmetic.rs:35:5 | ||
| | ||
LL | i *= 2; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:34:5 | ||
--> $DIR/integer_arithmetic.rs:38:11 | ||
| | ||
LL | i /= 2; | ||
| ^^^^^^ | ||
LL | i /= -1; | ||
| ^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:35:5 | ||
--> $DIR/integer_arithmetic.rs:39:5 | ||
| | ||
LL | i %= 2; | ||
| ^^^^^^ | ||
LL | i /= var1; | ||
| ^^^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:40:5 | ||
| | ||
LL | i /= var2; | ||
| ^^^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:43:11 | ||
| | ||
LL | i %= -1; | ||
| ^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:44:5 | ||
| | ||
LL | i %= var1; | ||
| ^^^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:45:5 | ||
| | ||
LL | i %= var2; | ||
| ^^^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:36:5 | ||
--> $DIR/integer_arithmetic.rs:46:5 | ||
| | ||
LL | i <<= 3; | ||
| ^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:37:5 | ||
--> $DIR/integer_arithmetic.rs:47:5 | ||
| | ||
LL | i >>= 2; | ||
| ^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:79:5 | ||
--> $DIR/integer_arithmetic.rs:89:5 | ||
| | ||
LL | 3 + &1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:80:5 | ||
--> $DIR/integer_arithmetic.rs:90:5 | ||
| | ||
LL | &3 + 1; | ||
| ^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:81:5 | ||
--> $DIR/integer_arithmetic.rs:91:5 | ||
| | ||
LL | &3 + &1; | ||
| ^^^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:86:5 | ||
--> $DIR/integer_arithmetic.rs:96:5 | ||
| | ||
LL | a + x | ||
| ^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:90:5 | ||
--> $DIR/integer_arithmetic.rs:100:5 | ||
| | ||
LL | x + y | ||
| ^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:94:5 | ||
--> $DIR/integer_arithmetic.rs:104:5 | ||
| | ||
LL | x + y | ||
| ^^^^^ | ||
|
||
error: integer arithmetic detected | ||
--> $DIR/integer_arithmetic.rs:98:5 | ||
--> $DIR/integer_arithmetic.rs:108:5 | ||
| | ||
LL | (&x + &y) | ||
| ^^^^^^^^^ | ||
|
||
error: aborting due to 21 previous errors | ||
error: aborting due to 27 previous errors | ||
|