Skip to content

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

Merged
llogiq merged 2 commits into
rust-lang:masterfrom
qsantos:master
Jan 9, 2025
Merged

Improve needless_as_bytes to also detect str::bytes()#13972
llogiq merged 2 commits into
rust-lang:masterfrom
qsantos:master

Conversation

@qsantos
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

llogiq commented Jan 9, 2025

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

@qsantos
Copy link
Copy Markdown
Contributor Author

qsantos commented Jan 9, 2025

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

@llogiq
Copy link
Copy Markdown
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
@qsantos
Copy link
Copy Markdown
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