]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/range_contains.rs
Auto merge of #97239 - jhpratt:remove-crate-vis, r=joshtriplett
[rust.git] / src / tools / clippy / 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_u32;
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
48 // Fix #6373
49 pub const fn in_range(a: i32) -> bool {
50     3 <= a && a <= 20
51 }