-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #6177 - rust-lang:manual-range-contains, r=flip1995
New lint: manual-range-contains This fixes #1110, at least for the contains-suggesting part. - \[x] Followed [lint naming conventions][lint_naming] - \[x] Added passing UI tests (including committed `.stderr` file) - \[x] `cargo test` passes locally - \[x] Executed `cargo dev update_lints` - \[x] Added lint documentation - \[x] Run `cargo dev fmt` --- changelog: new lint: manual-range-contains
- Loading branch information
Showing
7 changed files
with
354 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// run-rustfix | ||
|
||
#[warn(clippy::manual_range_contains)] | ||
#[allow(unused)] | ||
#[allow(clippy::no_effect)] | ||
#[allow(clippy::short_circuit_statement)] | ||
#[allow(clippy::unnecessary_operation)] | ||
fn main() { | ||
let x = 9_u32; | ||
|
||
// order shouldn't matter | ||
(8..12).contains(&x); | ||
(21..42).contains(&x); | ||
(1..100).contains(&x); | ||
|
||
// also with inclusive ranges | ||
(9..=99).contains(&x); | ||
(1..=33).contains(&x); | ||
(1..=999).contains(&x); | ||
|
||
// and the outside | ||
!(8..12).contains(&x); | ||
!(21..42).contains(&x); | ||
!(1..100).contains(&x); | ||
|
||
// also with the outside of inclusive ranges | ||
!(9..=99).contains(&x); | ||
!(1..=33).contains(&x); | ||
!(1..=999).contains(&x); | ||
|
||
// not a range.contains | ||
x > 8 && x < 12; // lower bound not inclusive | ||
x < 8 && x <= 12; // same direction | ||
x >= 12 && 12 >= x; // same bounds | ||
x < 8 && x > 12; // wrong direction | ||
|
||
x <= 8 || x >= 12; | ||
x >= 8 || x >= 12; | ||
x < 12 || 12 < x; | ||
x >= 8 || x <= 12; | ||
} |
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,41 @@ | ||
// run-rustfix | ||
|
||
#[warn(clippy::manual_range_contains)] | ||
#[allow(unused)] | ||
#[allow(clippy::no_effect)] | ||
#[allow(clippy::short_circuit_statement)] | ||
#[allow(clippy::unnecessary_operation)] | ||
fn main() { | ||
let x = 9_u32; | ||
|
||
// order shouldn't matter | ||
x >= 8 && x < 12; | ||
x < 42 && x >= 21; | ||
100 > x && 1 <= x; | ||
|
||
// also with inclusive ranges | ||
x >= 9 && x <= 99; | ||
x <= 33 && x >= 1; | ||
999 >= x && 1 <= x; | ||
|
||
// and the outside | ||
x < 8 || x >= 12; | ||
x >= 42 || x < 21; | ||
100 <= x || 1 > x; | ||
|
||
// also with the outside of inclusive ranges | ||
x < 9 || x > 99; | ||
x > 33 || x < 1; | ||
999 < x || 1 > x; | ||
|
||
// not a range.contains | ||
x > 8 && x < 12; // lower bound not inclusive | ||
x < 8 && x <= 12; // same direction | ||
x >= 12 && 12 >= x; // same bounds | ||
x < 8 && x > 12; // wrong direction | ||
|
||
x <= 8 || x >= 12; | ||
x >= 8 || x >= 12; | ||
x < 12 || 12 < x; | ||
x >= 8 || x <= 12; | ||
} |
Oops, something went wrong.