summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/from_iter_instead_of_collect.txt
blob: f3fd275972645c87168c6c141eb4eb95616e8fc9 (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
### What it does
Checks for `from_iter()` function calls on types that implement the `FromIterator`
trait.

### Why is this bad?
It is recommended style to use collect. See
[FromIterator documentation](https://doc.rust-lang.org/std/iter/trait.FromIterator.html)

### Example
```
let five_fives = std::iter::repeat(5).take(5);

let v = Vec::from_iter(five_fives);

assert_eq!(v, vec![5, 5, 5, 5, 5]);
```
Use instead:
```
let five_fives = std::iter::repeat(5).take(5);

let v: Vec<i32> = five_fives.collect();

assert_eq!(v, vec![5, 5, 5, 5, 5]);
```