summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/reversed_empty_ranges_fixable.rs
blob: b2e8bf33771acac68610d046227101c281dccaa5 (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
// run-rustfix
#![warn(clippy::reversed_empty_ranges)]

const ANSWER: i32 = 42;

fn main() {
    // These should be linted:

    (42..=21).for_each(|x| println!("{}", x));
    let _ = (ANSWER..21).filter(|x| x % 2 == 0).take(10).collect::<Vec<_>>();

    for _ in -21..=-42 {}
    for _ in 42u32..21u32 {}

    // These should be ignored as they are not empty ranges:

    (21..=42).for_each(|x| println!("{}", x));
    (21..42).for_each(|x| println!("{}", x));

    let arr = [1, 2, 3, 4, 5];
    let _ = &arr[1..=3];
    let _ = &arr[1..3];

    for _ in 21..=42 {}
    for _ in 21..42 {}

    // This range is empty but should be ignored, see issue #5689
    let _ = &arr[0..0];
}