blob: 39f481193866861d6f8fa68e96437c819e0fb273 (
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
|
### What it does
Checks for range expressions `x..y` where both `x` and `y`
are constant and `x` is greater or equal to `y`.
### Why is this bad?
Empty ranges yield no values so iterating them is a no-op.
Moreover, trying to use a reversed range to index a slice will panic at run-time.
### Example
```
fn main() {
(10..=0).for_each(|x| println!("{}", x));
let arr = [1, 2, 3, 4, 5];
let sub = &arr[3..1];
}
```
Use instead:
```
fn main() {
(0..=10).rev().for_each(|x| println!("{}", x));
let arr = [1, 2, 3, 4, 5];
let sub = &arr[1..3];
}
```
|