]> git.lizzy.rs Git - rust.git/commit
(#1955): Suggests `x > y` over `x >= y + 1` for ints
authorMichael Recachinas <mgr3yp@virginia.edu>
Sun, 17 Sep 2017 16:18:12 +0000 (17:18 +0100)
committerMichael Recachinas <mgr3yp@virginia.edu>
Sun, 17 Sep 2017 16:18:12 +0000 (17:18 +0100)
commitd7ea6addf06f0db99f4d21b229c7bfea223d827d
treeb595c3e601359e47a8b1d7909a67ac81be3f9dad
parent708a81809498780760d6992ee86dd0aa47d32bde
(#1955): Suggests `x > y` over `x >= y + 1` for ints

This module handles the following cases:
- `... >= ... + 1` and `... >= 1 + ...`
- `... - 1 >= ...` and `-1 + ... >= ...`
- `... + 1 <= ...` and `... + 1 <= ...`
- `... <= ... - 1` and `... <= -1 + ...`

Note: this only goes 1 level deep (i.e., does not constant-fold) and
does not currently simplify expressions. Examples of these
cases include:
```rust
let x = 1;
y >= y + x; // won't catch this case or any permutation

x + 1 >= y + 2; // won't catch this case

x + 1 - 1 >= y - 1 + 1; // WILL catch this case when it likely shouldn't
```
clippy_lints/src/int_plus_one.rs [new file with mode: 0644]