]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/range_plus_minus_one.fixed
New upstream version 1.65.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / range_plus_minus_one.fixed
1 // run-rustfix
2
3 #![allow(unused_parens)]
4 #![allow(clippy::iter_with_drain)]
5 fn f() -> usize {
6 42
7 }
8
9 macro_rules! macro_plus_one {
10 ($m: literal) => {
11 for i in 0..$m + 1 {
12 println!("{}", i);
13 }
14 };
15 }
16
17 macro_rules! macro_minus_one {
18 ($m: literal) => {
19 for i in 0..=$m - 1 {
20 println!("{}", i);
21 }
22 };
23 }
24
25 #[warn(clippy::range_plus_one)]
26 #[warn(clippy::range_minus_one)]
27 fn main() {
28 for _ in 0..2 {}
29 for _ in 0..=2 {}
30
31 for _ in 0..=3 {}
32 for _ in 0..=3 + 1 {}
33
34 for _ in 0..=5 {}
35 for _ in 0..=1 + 5 {}
36
37 for _ in 1..=1 {}
38 for _ in 1..=1 + 1 {}
39
40 for _ in 0..13 + 13 {}
41 for _ in 0..=13 - 7 {}
42
43 for _ in 0..=f() {}
44 for _ in 0..=(1 + f()) {}
45
46 let _ = ..11 - 1;
47 let _ = ..11;
48 let _ = ..11;
49 let _ = (1..=11);
50 let _ = ((f() + 1)..=f());
51
52 const ONE: usize = 1;
53 // integer consts are linted, too
54 for _ in 1..=ONE {}
55
56 let mut vec: Vec<()> = std::vec::Vec::new();
57 vec.drain(..);
58
59 macro_plus_one!(5);
60 macro_minus_one!(5);
61 }