]> git.lizzy.rs Git - rust.git/blob - src/docs/iter_on_empty_collections.txt
Merge remote-tracking branch 'upstream/master' into rustup
[rust.git] / src / docs / iter_on_empty_collections.txt
1 ### What it does
2
3 Checks for calls to `iter`, `iter_mut` or `into_iter` on empty collections
4
5 ### Why is this bad?
6
7 It is simpler to use the empty function from the standard library:
8
9 ### Example
10
11 ```
12 use std::{slice, option};
13 let a: slice::Iter<i32> = [].iter();
14 let f: option::IntoIter<i32> = None.into_iter();
15 ```
16 Use instead:
17 ```
18 use std::iter;
19 let a: iter::Empty<i32> = iter::empty();
20 let b: iter::Empty<i32> = iter::empty();
21 ```
22
23 ### Known problems
24
25 The type of the resulting iterator might become incompatible with its usage