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
Add redundant_as_str lint #11526
Add redundant_as_str lint #11526
Conversation
This lint checks for `as_str` on a `String` immediately followed by `as_bytes` or `is_empty` as those methods are available on `String` too. This could possibly also be extended to `&[u8]` in the future.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
tests/ui/redundant_as_str.rs
Outdated
#![warn(clippy::redundant_as_str)] | ||
|
||
fn main() { | ||
let _redundant = "Hello, world!".to_owned().as_str().as_bytes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please add tests for other methods that are not redundant to ensure the lint doesn't trigger in those cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a few more test cases that don't trigger the lint.
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This lint checks for
as_str
on aString
immediately followed byas_bytes
oris_empty
as those methods are available onString
too. This could possibly also be extended to&[u8]
in the future.changelog: New lint [
redundant_as_str
] #11526