diff options
| author | bors <bors@rust-lang.org> | 2023-05-18 02:11:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-18 02:11:02 +0000 |
| commit | 9cd483d5c915893dd675e43dc2c9945d513313bb (patch) | |
| tree | 3864fee2aad959a4589bce2fc532c7914226b07d | |
| parent | f3f6fd8920549107bd7506b35d445996840027e9 (diff) | |
| parent | 79eb06c6ec8838f6929ee54681de346f1b6bbde4 (diff) | |
| download | rust-9cd483d5c915893dd675e43dc2c9945d513313bb.tar.gz rust-9cd483d5c915893dd675e43dc2c9945d513313bb.zip | |
Auto merge of #10786 - mickvangelderen:remove-unnecessary-clone-from-needless-collect-example, r=Alexendoo
Remove unnecessary `clone` from `needless_collect` example
The example for [clippy::needless_collect](https://rust-lang.github.io/rust-clippy/master/#needless_collect) is written as follows:
```rust
let len = iterator.clone().collect::<Vec<_>>().len();
// should be
let len = iterator.count();
```
With this change, the unnecessary `clone()` is removed and the the standard
### Example
```rust
// original
```
Use instead:
```rust
// improved
```
structure is followed.
Discussion: https://github.com/rust-lang/rust-clippy/discussions/10784#discussion-5198885
changelog: [`needless_collect`]: Cleaned up the example in the lint documentation.
| -rw-r--r-- | clippy_lints/src/methods/mod.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index cb86917464b..02d4a9aa08f 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -3133,8 +3133,11 @@ declare_clippy_lint! { /// ### Example /// ```rust /// # let iterator = vec![1].into_iter(); - /// let len = iterator.clone().collect::<Vec<_>>().len(); - /// // should be + /// let len = iterator.collect::<Vec<_>>().len(); + /// ``` + /// Use instead: + /// ```rust + /// # let iterator = vec![1].into_iter(); /// let len = iterator.count(); /// ``` #[clippy::version = "1.30.0"] |
