summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/needless_range_loop.txt
blob: 583c09b284976e04960a0297612cd69e6e391669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
### What it does
Checks for looping over the range of `0..len` of some
collection just to get the values by index.

### Why is this bad?
Just iterating the collection itself makes the intent
more clear and is probably faster.

### Example
```
let vec = vec!['a', 'b', 'c'];
for i in 0..vec.len() {
    println!("{}", vec[i]);
}
```

Use instead:
```
let vec = vec!['a', 'b', 'c'];
for i in vec {
    println!("{}", i);
}
```