-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[unnecessary_to_owned
]: catch to_owned
on byte slice to create temporary &str
#11656
Conversation
r? @giraffate (rustbot has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #11694) made this pull request unmergeable. Please resolve the merge conflicts. |
(I claimed a few PRs, let's give this one to the lottery) r? clippy |
1412560
to
0449a36
Compare
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.
Looks fine. Just one small nit.
0449a36
to
ed9ccf6
Compare
Whoops. I thought I already merged this. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Closes #11648
Detects the pattern
&String::from_utf8(bytes.to_vec()).unwrap()
and suggestscore::str::from_utf8(bytes).unwrap()
, which avoids the unnecessary intermediate allocation.I decided to put this in the existing
unnecessary_to_owned
lint (rather than creating a new lint) for a few reasons:to_owned
family, e.g.to_vec
).to_vec()
, so this is in a way similar to the other cases caught byunnecessary_to_owned
, just through a bunch of type conversionsString
typechangelog: [
unnecessary_to_owned
]: catch&String::from_utf8(bytes.to_vec()).unwrap()
and suggestcore::str::from_utf8(bytes).unwrap()