2020-10-15 15:05:51 -05:00
|
|
|
// run-rustfix
|
|
|
|
|
2022-10-21 16:35:39 -05:00
|
|
|
#![warn(clippy::manual_range_contains)]
|
|
|
|
#![allow(unused)]
|
|
|
|
#![allow(clippy::no_effect)]
|
|
|
|
#![allow(clippy::short_circuit_statement)]
|
|
|
|
#![allow(clippy::unnecessary_operation)]
|
|
|
|
|
2020-10-15 15:05:51 -05:00
|
|
|
fn main() {
|
2022-04-28 22:54:58 -05:00
|
|
|
let x = 9_i32;
|
2020-10-15 15:05:51 -05:00
|
|
|
|
|
|
|
// 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;
|
2020-11-11 07:36:53 -06:00
|
|
|
|
|
|
|
// Fix #6315
|
|
|
|
let y = 3.;
|
|
|
|
y >= 0. && y < 1.;
|
|
|
|
y < 0. || y > 1.;
|
2022-04-28 22:54:58 -05:00
|
|
|
|
|
|
|
// handle negatives #8721
|
|
|
|
x >= -10 && x <= 10;
|
|
|
|
x >= 10 && x <= -10;
|
|
|
|
y >= -3. && y <= 3.;
|
|
|
|
y >= 3. && y <= -3.;
|
2022-05-24 10:50:12 -05:00
|
|
|
|
|
|
|
// Fix #8745
|
|
|
|
let z = 42;
|
|
|
|
(x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
|
|
|
|
(x < 0) || (x >= 10) || (z < 0) || (z >= 10);
|
2022-05-24 13:09:56 -05:00
|
|
|
// Make sure operators in parens don't give a breaking suggestion
|
|
|
|
((x % 2 == 0) || (x < 0)) || (x >= 10);
|
2020-10-15 15:05:51 -05:00
|
|
|
}
|
2020-11-25 02:07:50 -06:00
|
|
|
|
|
|
|
// Fix #6373
|
|
|
|
pub const fn in_range(a: i32) -> bool {
|
|
|
|
3 <= a && a <= 20
|
|
|
|
}
|
2022-10-21 16:35:39 -05:00
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.34"]
|
2022-10-21 16:35:39 -05:00
|
|
|
fn msrv_1_34() {
|
|
|
|
let x = 5;
|
|
|
|
x >= 8 && x < 34;
|
|
|
|
}
|
|
|
|
|
2022-11-19 06:50:02 -06:00
|
|
|
#[clippy::msrv = "1.35"]
|
2022-10-21 16:35:39 -05:00
|
|
|
fn msrv_1_35() {
|
|
|
|
let x = 5;
|
|
|
|
x >= 8 && x < 35;
|
|
|
|
}
|