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