summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/iter_on_empty_collections.txt
blob: 87c4ec12afae71b4592015e135452701cf64f0c1 (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
### What it does

Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections

### Why is this bad?

It is simpler to use the empty function from the standard library:

### Example

```
use std::{slice, option};
let a: slice::Iter<i32> = [].iter();
let f: option::IntoIter<i32> = None.into_iter();
```
Use instead:
```
use std::iter;
let a: iter::Empty<i32> = iter::empty();
let b: iter::Empty<i32> = iter::empty();
```

### Known problems

The type of the resulting iterator might become incompatible with its usage