Fix `needless_borrow` causing mutable borrows to be moved by Jarcho · Pull Reque...
source link: https://github.com/rust-lang/rust-clippy/pull/8217
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Conversation
fixes #8191
changelog: Fix needless_borrow
causing mutable borrows to be moved
changelog: Rename ref_in_deref
to needless_borrow
changelog: Suggest removing the borrow on method call receivers in needless_borrow
r? @camsteffen
(rust-highfive has picked a reviewer for you, use r? to override)
This now includes all cases covered by ref_in_deref
, which lints (&_).field
. The description for both would lead one to believe they lint the same thing. Should I just rename it?
I think we can remove/deprecate ref_in_deref
then?
Tangentially, I noticed the other day that we don't lint (*x).y
. I wonder where that could fit.
I'm (very slowly) working on an explicit deref lint. It would fit in there whenever that's done.
That successfully broke the changelog... Not really sure what to change there.
You need to add declare_deprecated_lint!
in clippy_lints/src/deprecated_lints.rs
and also add a deprecation test in tests/ui/deprecated.rs
. Then run cargo dev update_lints
and it should be good.
That would mean register_renamed
can't be used, right?
register_renamed
would make it so any usage of ref_in_deref
counts as needless_borrow
. That may or may not be a good thing but I think the lints are different enough that we don't want that? In any case the error message should point to needless_borrow
.
The description for ref_in
deref` is
Checks for references in expressions that use auto dereference.
The description for needless_borrow
is
Checks for address of operations (&) that are going to be dereferenced immediately by the compiler.
Those describe exactly the same thing. o the point where anything covered by one and not he other would be a clear false negative. Given that renaming sound like the appropriate thing to do.
Okay, good point. So I think you can just add register_renamed
by hand. To fix the error, change any ref_in_deref
links in the changelog to not be links anymore.
I was trying to avoid editing the changelog, but I don't see any other option.
One idea for the lint message but otherwise looks good. Please update "changelog" to include the lint rename and added functionality.
Squash some commits then will merge!
@bors r+
Commit c615140 has been approved by camsteffen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
No milestone
Successfully merging this pull request may close these issues.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK