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

Use len() instead of iter().count() #6262

Closed
camsteffen opened this issue Oct 28, 2020 · 2 comments · Fixed by #6791
Closed

Use len() instead of iter().count() #6262

camsteffen opened this issue Oct 28, 2020 · 2 comments · Fixed by #6791
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group T-middle Type: Probably requires verifiying types

Comments

@camsteffen
Copy link
Contributor

camsteffen commented Oct 28, 2020

What it does

Suggests using collection.len() instead of collection.iter().count().

Categories (optional)

  • clippy::complexity

What is the advantage of the recommended code over the original code

Simpler, idiomatic.

Drawbacks

None.

Example

vec.iter().count()

Could be written as:

vec.len()

Notes

  • Should work with all collections in std, and slices
  • Should also work with into_iter
  • Should also work with ExactSizeIterator::len
@camsteffen camsteffen added the A-lint Area: New lints label Oct 28, 2020
@camsteffen camsteffen added good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group T-middle Type: Probably requires verifiying types labels Feb 7, 2021
@TaKO8Ki
Copy link
Member

TaKO8Ki commented Feb 9, 2021

Hi. I'm interested in this issue so I'd like to tackle it.

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Feb 9, 2021

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy L-style Lint: Belongs in the style lint group T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants