-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Fix #9771 (unnecessary_to_owned
false positive)
#9796
Conversation
r? @flip1995 (rust-highfive has picked a reviewer for you, use r? to override) |
|
||
pub fn from(c: &[u8]) -> Key<Vec<u8>> { | ||
let v = [c].concat(); | ||
Key(v.to_vec()) |
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.
Note that this issue was not a false positive, ideally this should be corrected to Key(v)
, as .concat()
already returns a Vec<u8>
.
Key(v.to_vec()) | |
Key(v) |
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 take your point, but I think we have to treat the issue as a false positive for now.
Replacing v.to_vec()
with v
would move v
, and unnecessary_to_owned
doesn't currently have a way to tell whether a value can be moved.
I suspect it would be possible to incorporate something like possible_borrowers
from redundant_clone
. But I also think that would be a significant change and, hence, an enhancement.
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.
Alright, just wanted to make sure that you understood the issue correctly. I don't know much about the internals of clippy, so I can't help you with implementing this.
@bors r+ Thanks! |
Fix #9771 (`unnecessary_to_owned` false positive) Fixes #9771 In that issue's example(s), the lint tried to add a `&` to a value, which implicitly changed the type of a field to a reference. The fix is to add the reference to `receiver_ty` (the type of the receiver of the `to_owned`-like method), before passing `receiver_ty` to `can_change_type`. `can_change_type` properly rejects the modified `receiver_ty`. cc: `@mikerite` just because I think he was the author of `can_change_type`. changelog: fix `unnecessary_to_owned` false positive which implicitly tried to change the type of a field to a reference
@bors r- |
@bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #9771
In that issue's example(s), the lint tried to add a
&
to a value, which implicitly changed the type of a field to a reference. The fix is to add the reference toreceiver_ty
(the type of the receiver of theto_owned
-like method), before passingreceiver_ty
tocan_change_type
.can_change_type
properly rejects the modifiedreceiver_ty
.cc: @mikerite just because I think he was the author of
can_change_type
.changelog: fix
unnecessary_to_owned
false positive which implicitly tried to change the type of a field to a reference