Skip to content

Commit

Permalink
Fortify clippy tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Mar 8, 2023
1 parent 0d56034 commit a5a01b2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
8 changes: 5 additions & 3 deletions src/tools/clippy/tests/ui/erasing_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ impl core::ops::Mul<i32> for Vec1 {

#[allow(clippy::no_effect)]
#[warn(clippy::erasing_op)]
fn main() {
let x: u8 = 0;

fn test(x: u8) {
x * 0;
0 & x;
0 / x;
0 * Meter; // no error: Output type is different from the non-zero argument
0 * Vec1 { x: 5 };
Vec1 { x: 5 } * 0;
}

fn main() {
test(0)
}
10 changes: 5 additions & 5 deletions src/tools/clippy/tests/ui/erasing_op.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error: this operation will always return zero. This is likely not the intended outcome
--> $DIR/erasing_op.rs:37:5
--> $DIR/erasing_op.rs:35:5
|
LL | x * 0;
| ^^^^^
|
= note: `-D clippy::erasing-op` implied by `-D warnings`

error: this operation will always return zero. This is likely not the intended outcome
--> $DIR/erasing_op.rs:38:5
--> $DIR/erasing_op.rs:36:5
|
LL | 0 & x;
| ^^^^^

error: this operation will always return zero. This is likely not the intended outcome
--> $DIR/erasing_op.rs:39:5
--> $DIR/erasing_op.rs:37:5
|
LL | 0 / x;
| ^^^^^

error: this operation will always return zero. This is likely not the intended outcome
--> $DIR/erasing_op.rs:41:5
--> $DIR/erasing_op.rs:39:5
|
LL | 0 * Vec1 { x: 5 };
| ^^^^^^^^^^^^^^^^^

error: this operation will always return zero. This is likely not the intended outcome
--> $DIR/erasing_op.rs:42:5
--> $DIR/erasing_op.rs:40:5
|
LL | Vec1 { x: 5 } * 0;
| ^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/integer_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#[rustfmt::skip]
fn main() {
let mut i = 1i32;
let mut var1 = 0i32;
let mut var1 = 13i32;
let mut var2 = -1i32;
1 + i;
i * 2;
Expand Down
9 changes: 5 additions & 4 deletions src/tools/clippy/tests/ui/overflow_check_conditional.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#![warn(clippy::overflow_check_conditional)]

fn main() {
let a: u32 = 1;
let b: u32 = 2;
let c: u32 = 3;
fn test(a: u32, b: u32, c: u32) {
if a + b < a {}
if a > a + b {}
if a + b < b {}
Expand All @@ -23,3 +20,7 @@ fn main() {
if i > i + j {}
if i - j < i {}
}

fn main() {
test(1, 2, 3)
}
16 changes: 8 additions & 8 deletions src/tools/clippy/tests/ui/overflow_check_conditional.stderr
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
error: you are trying to use classic C overflow conditions that will fail in Rust
--> $DIR/overflow_check_conditional.rs:7:8
--> $DIR/overflow_check_conditional.rs:4:8
|
LL | if a + b < a {}
| ^^^^^^^^^
|
= note: `-D clippy::overflow-check-conditional` implied by `-D warnings`

error: you are trying to use classic C overflow conditions that will fail in Rust
--> $DIR/overflow_check_conditional.rs:8:8
--> $DIR/overflow_check_conditional.rs:5:8
|
LL | if a > a + b {}
| ^^^^^^^^^

error: you are trying to use classic C overflow conditions that will fail in Rust
--> $DIR/overflow_check_conditional.rs:9:8
--> $DIR/overflow_check_conditional.rs:6:8
|
LL | if a + b < b {}
| ^^^^^^^^^

error: you are trying to use classic C overflow conditions that will fail in Rust
--> $DIR/overflow_check_conditional.rs:10:8
--> $DIR/overflow_check_conditional.rs:7:8
|
LL | if b > a + b {}
| ^^^^^^^^^

error: you are trying to use classic C underflow conditions that will fail in Rust
--> $DIR/overflow_check_conditional.rs:11:8
--> $DIR/overflow_check_conditional.rs:8:8
|
LL | if a - b > b {}
| ^^^^^^^^^

error: you are trying to use classic C underflow conditions that will fail in Rust
--> $DIR/overflow_check_conditional.rs:12:8
--> $DIR/overflow_check_conditional.rs:9:8
|
LL | if b < a - b {}
| ^^^^^^^^^

error: you are trying to use classic C underflow conditions that will fail in Rust
--> $DIR/overflow_check_conditional.rs:13:8
--> $DIR/overflow_check_conditional.rs:10:8
|
LL | if a - b > a {}
| ^^^^^^^^^

error: you are trying to use classic C underflow conditions that will fail in Rust
--> $DIR/overflow_check_conditional.rs:14:8
--> $DIR/overflow_check_conditional.rs:11:8
|
LL | if a < a - b {}
| ^^^^^^^^^
Expand Down

0 comments on commit a5a01b2

Please sign in to comment.