]> git.lizzy.rs Git - rust.git/blob - tests/ui/range_contains.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / range_contains.rs
1 // run-rustfix
2
3 #[warn(clippy::manual_range_contains)]
4 #[allow(unused)]
5 #[allow(clippy::no_effect)]
6 #[allow(clippy::short_circuit_statement)]
7 #[allow(clippy::unnecessary_operation)]
8 fn main() {
9     let x = 9_i32;
10
11     // order shouldn't matter
12     x >= 8 && x < 12;
13     x < 42 && x >= 21;
14     100 > x && 1 <= x;
15
16     // also with inclusive ranges
17     x >= 9 && x <= 99;
18     x <= 33 && x >= 1;
19     999 >= x && 1 <= x;
20
21     // and the outside
22     x < 8 || x >= 12;
23     x >= 42 || x < 21;
24     100 <= x || 1 > x;
25
26     // also with the outside of inclusive ranges
27     x < 9 || x > 99;
28     x > 33 || x < 1;
29     999 < x || 1 > x;
30
31     // not a range.contains
32     x > 8 && x < 12; // lower bound not inclusive
33     x < 8 && x <= 12; // same direction
34     x >= 12 && 12 >= x; // same bounds
35     x < 8 && x > 12; // wrong direction
36
37     x <= 8 || x >= 12;
38     x >= 8 || x >= 12;
39     x < 12 || 12 < x;
40     x >= 8 || x <= 12;
41
42     // Fix #6315
43     let y = 3.;
44     y >= 0. && y < 1.;
45     y < 0. || y > 1.;
46
47     // handle negatives #8721
48     x >= -10 && x <= 10;
49     x >= 10 && x <= -10;
50     y >= -3. && y <= 3.;
51     y >= 3. && y <= -3.;
52
53     // Fix #8745
54     let z = 42;
55     (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
56     (x < 0) || (x >= 10) || (z < 0) || (z >= 10);
57     // Make sure operators in parens don't give a breaking suggestion
58     ((x % 2 == 0) || (x < 0)) || (x >= 10);
59 }
60
61 // Fix #6373
62 pub const fn in_range(a: i32) -> bool {
63     3 <= a && a <= 20
64 }