Rewrite overflow_check_conditional

This commit is contained in:
Jason Newcomb 2024-06-16 01:34:25 -04:00
parent f2c74e220b
commit aa371c37c2
3 changed files with 47 additions and 72 deletions

View file

@ -2,23 +2,14 @@
#![allow(clippy::needless_if)]
fn test(a: u32, b: u32, c: u32) {
if a + b < a {}
//~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust
//~| NOTE: `-D clippy::overflow-check-conditional` implied by `-D warnings`
if a > a + b {}
//~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust
if a + b < b {}
//~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust
if b > a + b {}
//~^ ERROR: you are trying to use classic C overflow conditions that will fail in Rust
if a + b < a {} //~ overflow_check_conditional
if a > a + b {} //~ overflow_check_conditional
if a + b < b {} //~ overflow_check_conditional
if b > a + b {} //~ overflow_check_conditional
if a - b > b {}
//~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus
if b < a - b {}
//~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus
if a - b > a {}
//~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus
if a < a - b {}
//~^ ERROR: you are trying to use classic C underflow conditions that will fail in Rus
if a - b > a {} //~ overflow_check_conditional
if a < a - b {} //~ overflow_check_conditional
if a + b < c {}
if c > a + b {}
if a - b < c {}

View file

@ -8,46 +8,34 @@ LL | if a + b < a {}
= help: to override `-D warnings` add `#[allow(clippy::overflow_check_conditional)]`
error: you are trying to use classic C overflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:8:8
--> tests/ui/overflow_check_conditional.rs:6:8
|
LL | if a > a + b {}
| ^^^^^^^^^
error: you are trying to use classic C overflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:10:8
--> tests/ui/overflow_check_conditional.rs:7:8
|
LL | if a + b < b {}
| ^^^^^^^^^
error: you are trying to use classic C overflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:12:8
--> tests/ui/overflow_check_conditional.rs:8:8
|
LL | if b > a + b {}
| ^^^^^^^^^
error: you are trying to use classic C underflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:14:8
|
LL | if a - b > b {}
| ^^^^^^^^^
error: you are trying to use classic C underflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:16:8
|
LL | if b < a - b {}
| ^^^^^^^^^
error: you are trying to use classic C underflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:18:8
error: you are trying to use classic C overflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:11:8
|
LL | if a - b > a {}
| ^^^^^^^^^
error: you are trying to use classic C underflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:20:8
error: you are trying to use classic C overflow conditions that will fail in Rust
--> tests/ui/overflow_check_conditional.rs:12:8
|
LL | if a < a - b {}
| ^^^^^^^^^
error: aborting due to 8 previous errors
error: aborting due to 6 previous errors