Skip to content
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

suggest iterator.count() instead of iterator.collect<Vec<_>>.len() #3034

Closed
matthiaskrgr opened this issue Aug 11, 2018 · 2 comments
Closed

Comments

@matthiaskrgr
Copy link
Member

instead of doing something like

let len = iterator.collect<Vec<_>>.len();

we might want to suggest

let len = iterator.count();

however, .count() consumes the iterator so I am not sure if this is always applicable.

@shssoichiro
Copy link
Contributor

+1, this should always be safe if .collect().len() is done inline--the intermediate collected data structure is guaranteed to never be reused in this case.

@shssoichiro
Copy link
Contributor

I'll go ahead and pick this up.

shssoichiro added a commit to shssoichiro/rust-clippy that referenced this issue Aug 31, 2018
Handles cases of `.collect().len()`, `.collect().is_empty()`, and
`.collect().contains()`. This lint is intended to be generic enough to
be added to at a later time with other similar patterns that could be
optimized.

Closes rust-lang#3034
shssoichiro added a commit to shssoichiro/rust-clippy that referenced this issue Aug 31, 2018
Handles cases of `.collect().len()`, `.collect().is_empty()`, and
`.collect().contains()`. This lint is intended to be generic enough to
be added to at a later time with other similar patterns that could be
optimized.

Closes rust-lang#3034
shssoichiro added a commit to shssoichiro/rust-clippy that referenced this issue Sep 4, 2018
Handles cases of `.collect().len()`, `.collect().is_empty()`, and
`.collect().contains()`. This lint is intended to be generic enough to
be added to at a later time with other similar patterns that could be
optimized.

Closes rust-lang#3034
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants