]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / reversed_empty_ranges_loops_fixable.fixed
CommitLineData
f20569fa
XL
1// run-rustfix
2#![warn(clippy::reversed_empty_ranges)]
3
4fn main() {
5 const MAX_LEN: usize = 42;
6
7 for i in (0..10).rev() {
8 println!("{}", i);
9 }
10
11 for i in (0..=10).rev() {
12 println!("{}", i);
13 }
14
15 for i in (0..MAX_LEN).rev() {
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 (0..10).rev().map(|x| x * 2) {
35 println!("{}", i);
36 }
37
38 // testing that the empty range lint folds constants
39 for i in (5 + 4..10).rev() {
40 println!("{}", i);
41 }
42
43 for i in ((3 - 1)..(5 + 2)).rev() {
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}