Skip to content

Generalize iter_cloned_collect to .copied() #6703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kpreid opened this issue Feb 9, 2021 · 4 comments · Fixed by #8006
Closed

Generalize iter_cloned_collect to .copied() #6703

kpreid opened this issue Feb 9, 2021 · 4 comments · Fixed by #8006
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good first issue These issues are a good way to get started with Clippy

Comments

@kpreid
Copy link
Contributor

kpreid commented Feb 9, 2021

I ran Clippy on some previously unlinted code and found that it reported that

some_slice.iter().cloned().collect::<Vec<_>>()

could be replaced with some_slice.to_vec(), but, did not report cases where I had happened to write

some_slice.iter().copied().collect::<Vec<_>>()

instead. Perhaps it would make sense to generalize iter_cloned_collect to also detect uses of .copied(), or add a corresponding lint if they should be kept separate for some reason.

@giraffate
Copy link
Contributor

Thanks for suggesting enhancement! But it seems to be a duplicate of #3870, so I'm closing this.

@kpreid
Copy link
Contributor Author

kpreid commented Feb 9, 2021

I think these are different issues: that issue talks about a lint replacing .cloned() with .copied(). In this issue, I am proposing that the lint would recommend replacing a chain containing .copied() with .to_vec().

Sorry if my two-code-blocks formatting made it overly easy to read this as proposing the first block being replaced with the second.

(Incidentally, I checked the standard library source and .to_vec() uses Copy when available, so this would not have any performance regression.)

@giraffate
Copy link
Contributor

Oh, sorry for my misunderstanding. I reopen this.

@giraffate giraffate reopened this Feb 9, 2021
@giraffate giraffate added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good first issue These issues are a good way to get started with Clippy labels Feb 9, 2021
@HarrisonMc555
Copy link
Contributor

I'll try implementing this! @rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good first issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants