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