summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/range_plus_minus_one.fixed
blob: a16a3e54d45eadaaf8025b6eadb94b4a2847076d (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
59
60
61
// run-rustfix

#![allow(unused_parens)]
#![allow(clippy::iter_with_drain)]
fn f() -> usize {
    42
}

macro_rules! macro_plus_one {
    ($m: literal) => {
        for i in 0..$m + 1 {
            println!("{}", i);
        }
    };
}

macro_rules! macro_minus_one {
    ($m: literal) => {
        for i in 0..=$m - 1 {
            println!("{}", i);
        }
    };
}

#[warn(clippy::range_plus_one)]
#[warn(clippy::range_minus_one)]
fn main() {
    for _ in 0..2 {}
    for _ in 0..=2 {}

    for _ in 0..=3 {}
    for _ in 0..=3 + 1 {}

    for _ in 0..=5 {}
    for _ in 0..=1 + 5 {}

    for _ in 1..=1 {}
    for _ in 1..=1 + 1 {}

    for _ in 0..13 + 13 {}
    for _ in 0..=13 - 7 {}

    for _ in 0..=f() {}
    for _ in 0..=(1 + f()) {}

    let _ = ..11 - 1;
    let _ = ..11;
    let _ = ..11;
    let _ = (1..=11);
    let _ = ((f() + 1)..=f());

    const ONE: usize = 1;
    // integer consts are linted, too
    for _ in 1..=ONE {}

    let mut vec: Vec<()> = std::vec::Vec::new();
    vec.drain(..);

    macro_plus_one!(5);
    macro_minus_one!(5);
}