-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't warn about modulo arithmetic when comparing to zero
Add lint configuration for `modulo_arithmetic` Collect meta-data
- Loading branch information
Showing
11 changed files
with
122 additions
and
5 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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
allow-comparison-to-zero = false |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#![warn(clippy::modulo_arithmetic)] | ||
|
||
fn main() { | ||
let a = -1; | ||
let b = 2; | ||
let c = a % b == 0; | ||
let c = a % b != 0; | ||
let c = 0 == a % b; | ||
let c = 0 != a % b; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
error: you are using modulo operator on types that might have different signs | ||
--> $DIR/modulo_arithmetic.rs:6:13 | ||
| | ||
LL | let c = a % b == 0; | ||
| ^^^^^ | ||
| | ||
= note: double check for expected result especially when interoperating with different languages | ||
= note: or consider using `rem_euclid` or similar function | ||
= note: `-D clippy::modulo-arithmetic` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::modulo_arithmetic)]` | ||
|
||
error: you are using modulo operator on types that might have different signs | ||
--> $DIR/modulo_arithmetic.rs:7:13 | ||
| | ||
LL | let c = a % b != 0; | ||
| ^^^^^ | ||
| | ||
= note: double check for expected result especially when interoperating with different languages | ||
= note: or consider using `rem_euclid` or similar function | ||
|
||
error: you are using modulo operator on types that might have different signs | ||
--> $DIR/modulo_arithmetic.rs:8:18 | ||
| | ||
LL | let c = 0 == a % b; | ||
| ^^^^^ | ||
| | ||
= note: double check for expected result especially when interoperating with different languages | ||
= note: or consider using `rem_euclid` or similar function | ||
|
||
error: you are using modulo operator on types that might have different signs | ||
--> $DIR/modulo_arithmetic.rs:9:18 | ||
| | ||
LL | let c = 0 != a % b; | ||
| ^^^^^ | ||
| | ||
= note: double check for expected result especially when interoperating with different languages | ||
= note: or consider using `rem_euclid` or similar function | ||
|
||
error: aborting due to 4 previous errors | ||
|
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