]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.rs
Auto merge of #84620 - Dylan-DPC:rollup-wkv97im, r=Dylan-DPC
[rust.git] / src / tools / clippy / tests / ui / reversed_empty_ranges_loops_fixable.rs
1 // run-rustfix
2 #![warn(clippy::reversed_empty_ranges)]
3
4 fn main() {
5     const MAX_LEN: usize = 42;
6
7     for i in 10..0 {
8         println!("{}", i);
9     }
10
11     for i in 10..=0 {
12         println!("{}", i);
13     }
14
15     for i in MAX_LEN..0 {
16         println!("{}", i);
17     }
18
19     for i in 5..=5 {
20         // not an error, this is the range with only one element “5”
21         println!("{}", i);
22     }
23
24     for i in 0..10 {
25         // not an error, the start index is less than the end index
26         println!("{}", i);
27     }
28
29     for i in -10..0 {
30         // not an error
31         println!("{}", i);
32     }
33
34     for i in (10..0).map(|x| x * 2) {
35         println!("{}", i);
36     }
37
38     // testing that the empty range lint folds constants
39     for i in 10..5 + 4 {
40         println!("{}", i);
41     }
42
43     for i in (5 + 2)..(3 - 1) {
44         println!("{}", i);
45     }
46
47     for i in (2 * 2)..(2 * 3) {
48         // no error, 4..6 is fine
49         println!("{}", i);
50     }
51
52     let x = 42;
53     for i in x..10 {
54         // no error, not constant-foldable
55         println!("{}", i);
56     }
57 }