summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/reversed_empty_ranges_loops_fixable.fixed
blob: 78401e463d50d8c7c195a2291d0aabd69cce5a65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// run-rustfix
#![warn(clippy::reversed_empty_ranges)]
#![allow(clippy::uninlined_format_args)]

fn main() {
    const MAX_LEN: usize = 42;

    for i in (0..10).rev() {
        println!("{}", i);
    }

    for i in (0..=10).rev() {
        println!("{}", i);
    }

    for i in (0..MAX_LEN).rev() {
        println!("{}", i);
    }

    for i in 5..=5 {
        // not an error, this is the range with only one element “5”
        println!("{}", i);
    }

    for i in 0..10 {
        // not an error, the start index is less than the end index
        println!("{}", i);
    }

    for i in -10..0 {
        // not an error
        println!("{}", i);
    }

    for i in (0..10).rev().map(|x| x * 2) {
        println!("{}", i);
    }

    // testing that the empty range lint folds constants
    for i in (5 + 4..10).rev() {
        println!("{}", i);
    }

    for i in ((3 - 1)..(5 + 2)).rev() {
        println!("{}", i);
    }

    for i in (2 * 2)..(2 * 3) {
        // no error, 4..6 is fine
        println!("{}", i);
    }

    let x = 42;
    for i in x..10 {
        // no error, not constant-foldable
        println!("{}", i);
    }
}