Skip to content

Commit

Permalink
Auto merge of rust-lang#10786 - mickvangelderen:remove-unnecessary-cl…
Browse files Browse the repository at this point in the history
…one-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: rust-lang/rust-clippy#10784 (comment)

changelog: [`needless_collect`]: Cleaned up the example in the lint documentation.
  • Loading branch information
bors committed May 18, 2023
2 parents f3f6fd8 + 79eb06c commit 9cd483d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 9cd483d

Please sign in to comment.