summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/iter_overeager_cloned.txt
blob: 2f902a0c2db4d1c6295ef59e3a05f977eb07377e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
### What it does
Checks for usage of `_.cloned().<func>()` where call to `.cloned()` can be postponed.

### Why is this bad?
It's often inefficient to clone all elements of an iterator, when eventually, only some
of them will be consumed.

### Known Problems
This `lint` removes the side of effect of cloning items in the iterator.
A code that relies on that side-effect could fail.

### Examples
```
vec.iter().cloned().take(10);
vec.iter().cloned().last();
```

Use instead:
```
vec.iter().take(10).cloned();
vec.iter().last().cloned();
```