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

Lint suggesting to replace str::bytes().count() with str::len() #8083

Closed
wooster0 opened this issue Dec 6, 2021 · 6 comments · Fixed by #8711
Closed

Lint suggesting to replace str::bytes().count() with str::len() #8083

wooster0 opened this issue Dec 6, 2021 · 6 comments · Fixed by #8711
Assignees
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@wooster0
Copy link

wooster0 commented Dec 6, 2021

What it does

It checks for str::bytes().count() and suggests replacing it with str::len() that does the same but shorter and possibly more performant.

Extra: can something like this be done for https://doc.rust-lang.org/std/io/trait.Read.html#method.bytes too?

Lint Name

bytes_count_to_len

Category

complexity

Advantage

  • Might be more performant
  • Shorter
  • Possibly easier to read

Drawbacks

No response

Example

fn main() {
    "hello".bytes().count();
}

Could be written as:

fn main() {
    "hello".len();
}
@wooster0 wooster0 added the A-lint Area: New lints label Dec 6, 2021
@giraffate giraffate added the good-first-issue These issues are a good way to get started with Clippy label Dec 8, 2021
@sivchari
Copy link

sivchari commented Dec 10, 2021

Can I try this ?

@sivchari
Copy link

@rustbot claim

@nindalf
Copy link
Contributor

nindalf commented Jan 26, 2022

@sivchari are you still working on this?

@sivchari
Copy link

I don't have no progress, so I unassign me.
@rustbot release-assignment

@chaseruskin
Copy link
Contributor

chaseruskin commented Jan 28, 2022

Since this issue has become unassigned, I am wondering if I could work on this issue?

@chaseruskin
Copy link
Contributor

@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
Projects
None yet
5 participants