mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-24 19:37:20 +00:00
Add tests for 'int_plus_one'
This commit is contained in:
parent
535302efda
commit
bb40bd68a4
2 changed files with 53 additions and 0 deletions
18
tests/ui/int_plus_one.rs
Normal file
18
tests/ui/int_plus_one.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(clippy)]
|
||||||
|
|
||||||
|
#[allow(no_effect, unnecessary_operation)]
|
||||||
|
#[warn(int_plus_one)]
|
||||||
|
fn main() {
|
||||||
|
let x = 1i32;
|
||||||
|
let y = 0i32;
|
||||||
|
|
||||||
|
x >= y + 1;
|
||||||
|
y + 1 <= x;
|
||||||
|
|
||||||
|
x - 1 >= y;
|
||||||
|
y <= x - 1;
|
||||||
|
|
||||||
|
x > y; // should be ok
|
||||||
|
y < x; // should be ok
|
||||||
|
}
|
35
tests/ui/int_plus_one.stderr
Normal file
35
tests/ui/int_plus_one.stderr
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
error: Unnecessary `>= y + 1` or `x - 1 >=`
|
||||||
|
--> $DIR/int_plus_one.rs:10:5
|
||||||
|
|
|
||||||
|
10 | x >= y + 1;
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: `-D int-plus-one` implied by `-D warnings`
|
||||||
|
= help: Consider reducing `x >= y + 1` or `x - 1 >= y` to `x > y`
|
||||||
|
|
||||||
|
error: Unnecessary `>= y + 1` or `x - 1 >=`
|
||||||
|
--> $DIR/int_plus_one.rs:11:5
|
||||||
|
|
|
||||||
|
11 | y + 1 <= x;
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: Consider reducing `x >= y + 1` or `x - 1 >= y` to `x > y`
|
||||||
|
|
||||||
|
error: Unnecessary `>= y + 1` or `x - 1 >=`
|
||||||
|
--> $DIR/int_plus_one.rs:13:5
|
||||||
|
|
|
||||||
|
13 | x - 1 >= y;
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: Consider reducing `x >= y + 1` or `x - 1 >= y` to `x > y`
|
||||||
|
|
||||||
|
error: Unnecessary `>= y + 1` or `x - 1 >=`
|
||||||
|
--> $DIR/int_plus_one.rs:14:5
|
||||||
|
|
|
||||||
|
14 | y <= x - 1;
|
||||||
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
|
= help: Consider reducing `x >= y + 1` or `x - 1 >= y` to `x > y`
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
Loading…
Add table
Reference in a new issue