-
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
New lint against Self
as an arbitrary self type
#5869
Conversation
r? @flip1995 (rust_highfive has picked a reviewer for you, use r? to override) |
3b74a9a
to
b34bf8b
Compare
r? @ebroto |
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.
Thanks for your contribution! I left some thoughts.
cc @flip1995
69ef96b
to
fb3b7dd
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.
This looks great! Just two minor nits.
Also, could you update the PR description to specify the changelog
line? Something like:
changelog: * [`needless_arbitrary_self_type`] [#5869](https://github.com/rust-lang/rust-clippy/pull/5869)
This will help the person writing the CHANGELOG.
And now that we're at it, changing rel #5861
to Fixes #5861
will automatically close the issue after merging, which I think it's relevant in this case.
LGTM, thanks! @flip1995 I think this is ready to merge if you agree |
LL | pub fn mut_ref_mut_bad(mut self: &mut Self) { | ||
| ^^^^^^^^^^^^^^^^^^^ help: consider to change this parameter to: `&mut self` |
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.
Is this semantically the same?
I think the original code makes the reference mutable. The suggested code is just a mutable reference.
Is mut &mut self
valid code? 🤔
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.
To answer my question: Yes this is the case: Playground
Admittedly this seems like an constructed example for mut self: &mut Self
, but code similar to this does actually exist. (IIRC tokio has similar code in its codebase)
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.
You're right, the suggestion is only equivalent for the mut self: Self
case, and mut &mut self
triggers a parser error.
Everything else LGTM 👍 |
ddadedd
to
bfe610c
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.
Thanks! Waiting for rustup.
@bors r=ebroto,flip1995 rollup |
📌 Commit bfe610c has been approved by |
Rollup of 5 pull requests Successful merges: - #5825 (Add the new lint `same_item_push`) - #5869 (New lint against `Self` as an arbitrary self type) - #5870 (enable #[allow(clippy::unsafe_derive_deserialize)]) - #5871 (Lint .min(x).max(y) with x < y) - #5874 (Make the docs clearer for new contributors) Failed merges: r? @ghost changelog: rollup
Fixes #5861
changelog: * [
needless_arbitrary_self_type
] #5869