]> git.lizzy.rs Git - rust.git/blob - tests/ui/range_contains.rs
[`excessive_bools`] lint trait functions even without bodies
[rust.git] / tests / ui / range_contains.rs
1 // run-rustfix
2
3 #![feature(custom_inner_attributes)]
4 #![warn(clippy::manual_range_contains)]
5 #![allow(unused)]
6 #![allow(clippy::no_effect)]
7 #![allow(clippy::short_circuit_statement)]
8 #![allow(clippy::unnecessary_operation)]
9
10 fn main() {
11     let x = 9_i32;
12
13     // order shouldn't matter
14     x >= 8 && x < 12;
15     x < 42 && x >= 21;
16     100 > x && 1 <= x;
17
18     // also with inclusive ranges
19     x >= 9 && x <= 99;
20     x <= 33 && x >= 1;
21     999 >= x && 1 <= x;
22
23     // and the outside
24     x < 8 || x >= 12;
25     x >= 42 || x < 21;
26     100 <= x || 1 > x;
27
28     // also with the outside of inclusive ranges
29     x < 9 || x > 99;
30     x > 33 || x < 1;
31     999 < x || 1 > x;
32
33     // not a range.contains
34     x > 8 && x < 12; // lower bound not inclusive
35     x < 8 && x <= 12; // same direction
36     x >= 12 && 12 >= x; // same bounds
37     x < 8 && x > 12; // wrong direction
38
39     x <= 8 || x >= 12;
40     x >= 8 || x >= 12;
41     x < 12 || 12 < x;
42     x >= 8 || x <= 12;
43
44     // Fix #6315
45     let y = 3.;
46     y >= 0. && y < 1.;
47     y < 0. || y > 1.;
48
49     // handle negatives #8721
50     x >= -10 && x <= 10;
51     x >= 10 && x <= -10;
52     y >= -3. && y <= 3.;
53     y >= 3. && y <= -3.;
54
55     // Fix #8745
56     let z = 42;
57     (x >= 0) && (x <= 10) && (z >= 0) && (z <= 10);
58     (x < 0) || (x >= 10) || (z < 0) || (z >= 10);
59     // Make sure operators in parens don't give a breaking suggestion
60     ((x % 2 == 0) || (x < 0)) || (x >= 10);
61 }
62
63 // Fix #6373
64 pub const fn in_range(a: i32) -> bool {
65     3 <= a && a <= 20
66 }
67
68 fn msrv_1_34() {
69     #![clippy::msrv = "1.34"]
70
71     let x = 5;
72     x >= 8 && x < 34;
73 }
74
75 fn msrv_1_35() {
76     #![clippy::msrv = "1.35"]
77
78     let x = 5;
79     x >= 8 && x < 35;
80 }