-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Extend UNNECESSARY_TO_OWNED
to handle split
#11871
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
Extend UNNECESSARY_TO_OWNED
to handle split
#11871
Conversation
r? @llogiq |
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.
The code looks good, some more tests would be nice though.
fn main() { | ||
let _ = "a".to_string().split('a').next().unwrap(); | ||
//~^ ERROR: unnecessary use of `to_string` | ||
let _ = "a".to_owned().split('a').next().unwrap(); |
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'd like to see a test splitting by a &str and perhaps a counter-test that calls split by ()
which is implemented by a custom trait (if that is even possible?).
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.
Implementing the Pattern
trait is... quite a lot of code. So instead, I added checks for both char
and str
and also added the equivalent tests on slice
.
efddb33
to
238c5f9
Compare
Updated! |
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #9965.
When you have
to_string().split('a')
or equivalent, it'll suggest to remove theto_owned
/to_string
part.r? @flip1995
changelog: Extend
UNNECESSARY_TO_OWNED
to handlesplit