2022-10-23 13:18:45 +00:00
|
|
|
#![warn(clippy::manual_range_contains)]
|
|
|
|
#![allow(unused)]
|
|
|
|
#![allow(clippy::no_effect)]
|
|
|
|
#![allow(clippy::short_circuit_statement)]
|
|
|
|
#![allow(clippy::unnecessary_operation)]
|
2023-08-11 12:05:13 +00:00
|
|
|
#![allow(clippy::impossible_comparisons)]
|
|
|
|
#![allow(clippy::redundant_comparisons)]
|
2022-10-23 13:18:45 +00:00
|
|
|
|
2020-10-28 22:36:07 +00:00
|
|
|
fn main() {
|
2022-05-21 11:24:00 +00:00
|
|
|
let x = 9_i32;
|
2020-10-28 22:36:07 +00:00
|
|
|
|
|
|
|
// 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;
|
2020-11-23 12:51:04 +00:00
|
|
|
|
|
|
|
// Fix #6315
|
|
|
|
let y = 3.;
|
|
|
|
(0. ..1.).contains(&y);
|
|
|
|
!(0. ..=1.).contains(&y);
|
2022-05-21 11:24:00 +00:00
|
|
|
|
|
|
|
// handle negatives #8721
|
|
|
|
(-10..=10).contains(&x);
|
|
|
|
x >= 10 && x <= -10;
|
|
|
|
(-3. ..=3.).contains(&y);
|
|
|
|
y >= 3. && y <= -3.;
|
2022-06-04 11:34:07 +00:00
|
|
|
|
|
|
|
// Fix #8745
|
|
|
|
let z = 42;
|
|
|
|
(0..=10).contains(&x) && (0..=10).contains(&z);
|
|
|
|
!(0..10).contains(&x) || !(0..10).contains(&z);
|
|
|
|
// Make sure operators in parens don't give a breaking suggestion
|
|
|
|
((x % 2 == 0) || (x < 0)) || (x >= 10);
|
2020-10-28 22:36:07 +00:00
|
|
|
}
|
2020-12-20 16:19:49 +00:00
|
|
|
|
|
|
|
// Fix #6373
|
|
|
|
pub const fn in_range(a: i32) -> bool {
|
|
|
|
3 <= a && a <= 20
|
|
|
|
}
|
2022-10-23 13:18:45 +00:00
|
|
|
|
2022-12-01 17:29:38 +00:00
|
|
|
#[clippy::msrv = "1.34"]
|
2022-10-23 13:18:45 +00:00
|
|
|
fn msrv_1_34() {
|
|
|
|
let x = 5;
|
|
|
|
x >= 8 && x < 34;
|
|
|
|
}
|
|
|
|
|
2022-12-01 17:29:38 +00:00
|
|
|
#[clippy::msrv = "1.35"]
|
2022-10-23 13:18:45 +00:00
|
|
|
fn msrv_1_35() {
|
|
|
|
let x = 5;
|
|
|
|
(8..35).contains(&x);
|
|
|
|
}
|