Skip to content

str::split instead of to_string().split() #9965

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
lexeyOK opened this issue Nov 27, 2022 · 2 comments · Fixed by #11871
Closed

str::split instead of to_string().split() #9965

lexeyOK opened this issue Nov 27, 2022 · 2 comments · Fixed by #11871
Labels
A-lint Area: New lints

Comments

@lexeyOK
Copy link

lexeyOK commented Nov 27, 2022

What it does

It suggests to use str::split instead of chaining .to_string().split().

Lint Name

str_split_instead_of_to_string_chain

Category

style

Advantage

shorter, there is no overhead as far as i know
https://godbolt.org/z/ET7Y55P4E

Drawbacks

No response

Example

fn count_string(s: &str) -> usize {
    s.to_string().split(",").count()
}

Could be written as:

fn count_str(s: &str) -> usize {
    s.split(",").count()
}
@lexeyOK lexeyOK added the A-lint Area: New lints label Nov 27, 2022
@Alexendoo
Copy link
Member

Would be a good enhancement to unnecessary_to_owned

@GuillaumeGomez
Copy link
Member

Sending a PR shortly to handle this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants