]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/range_contains.fixed
Rollup merge of #99474 - aDotInTheVoid:rustdoc-json-noinline-test-cleanup, r=CraftSpider
[rust.git] / src / tools / clippy / tests / ui / range_contains.fixed
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     (8..12).contains(&x);
13     (21..42).contains(&x);
14     (1..100).contains(&x);
15
16     // also with inclusive ranges
17     (9..=99).contains(&x);
18     (1..=33).contains(&x);
19     (1..=999).contains(&x);
20
21     // and the outside
22     !(8..12).contains(&x);
23     !(21..42).contains(&x);
24     !(1..100).contains(&x);
25
26     // also with the outside of inclusive ranges
27     !(9..=99).contains(&x);
28     !(1..=33).contains(&x);
29     !(1..=999).contains(&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     (0. ..1.).contains(&y);
45     !(0. ..=1.).contains(&y);
46
47     // handle negatives #8721
48     (-10..=10).contains(&x);
49     x >= 10 && x <= -10;
50     (-3. ..=3.).contains(&y);
51     y >= 3. && y <= -3.;
52
53     // Fix #8745
54     let z = 42;
55     (0..=10).contains(&x) && (0..=10).contains(&z);
56     !(0..10).contains(&x) || !(0..10).contains(&z);
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 }