Skip to content

Improve needless_as_bytes to also detect str::bytes() #13972

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

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

qsantos
Copy link
Contributor

@qsantos qsantos commented Jan 9, 2025

I ran Clippy on some projects after upgrading to 1.84, which found a needless use of as_bytes(). It made me notice that the code was also using bytes() needlessly in other places. This PR improves on the as_bytes() lint to also lint bytes().


changelog: none

We are checking that we are calling the `as_bytes()` method of `String`
or `str`. Checking that it returns a `slice()` does not add anything.
This builds upon the lint for `str::as_bytes()`, and also covers
needless uses of the iterator version `str::bytes()`.
@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2025

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 9, 2025
@llogiq
Copy link
Contributor

llogiq commented Jan 9, 2025

Please run cargo dev fmt and commit&push the changes.

@qsantos
Copy link
Contributor Author

qsantos commented Jan 9, 2025

Sorry, took me a while to realize I had simply not pushed my branch!

@llogiq
Copy link
Contributor

llogiq commented Jan 9, 2025

Happens to the best of us.

Thank you!

@llogiq llogiq added this pull request to the merge queue Jan 9, 2025
Merged via the queue into rust-lang:master with commit 197d58d Jan 9, 2025
9 checks passed
@qsantos
Copy link
Contributor Author

qsantos commented Jan 10, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants