]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/range_contains.fixed
Rollup merge of #103333 - chenyukang:yukang/fix-103143, r=wesleywiser
[rust.git] / src / tools / clippy / tests / ui / range_contains.fixed
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     (8..12).contains(&x);
15     (21..42).contains(&x);
16     (1..100).contains(&x);
17
18     // also with inclusive ranges
19     (9..=99).contains(&x);
20     (1..=33).contains(&x);
21     (1..=999).contains(&x);
22
23     // and the outside
24     !(8..12).contains(&x);
25     !(21..42).contains(&x);
26     !(1..100).contains(&x);
27
28     // also with the outside of inclusive ranges
29     !(9..=99).contains(&x);
30     !(1..=33).contains(&x);
31     !(1..=999).contains(&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     (0. ..1.).contains(&y);
47     !(0. ..=1.).contains(&y);
48
49     // handle negatives #8721
50     (-10..=10).contains(&x);
51     x >= 10 && x <= -10;
52     (-3. ..=3.).contains(&y);
53     y >= 3. && y <= -3.;
54
55     // Fix #8745
56     let z = 42;
57     (0..=10).contains(&x) && (0..=10).contains(&z);
58     !(0..10).contains(&x) || !(0..10).contains(&z);
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     (8..35).contains(&x);
80 }