]> git.lizzy.rs Git - rust.git/blob - tests/ui/reversed_empty_ranges_loops_fixable.fixed
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / reversed_empty_ranges_loops_fixable.fixed
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 (0..10).rev() {
9         println!("{}", i);
10     }
11
12     for i in (0..=10).rev() {
13         println!("{}", i);
14     }
15
16     for i in (0..MAX_LEN).rev() {
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 (0..10).rev().map(|x| x * 2) {
36         println!("{}", i);
37     }
38
39     // testing that the empty range lint folds constants
40     for i in (5 + 4..10).rev() {
41         println!("{}", i);
42     }
43
44     for i in ((3 - 1)..(5 + 2)).rev() {
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 }