-
Notifications
You must be signed in to change notification settings - Fork 1.3k
style: use Self
to avoid unnecessary repetition
#3396
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
Conversation
In `impl`s, `Self` can be used instead of the struct/enum being implemented, to reduce unnecessary repetition. This commit uses `Self` as often as possible. This fixes the `use_self` clippy lint.
Copying over the previous discussion from #3394
|
Yeah, let's be a bit more conservative and not change any of the places that David had some concerns about. You can still enable the lint, just |
NOTE: This commit adds multiple `#[allow]`s where Clippy would otherwise warn about `Self` being allowed.
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 think everything here is fine, if I didn't miss something, it's really just constructors and enum variants (and a few signatures).
With all checks passing, this is ready to merge 👌 |
@jplatte if you want to change some of the allows to |
Thanks everyone! |
Motivation
This PR is part of the broader PR #3394 (Activate more lints)
Repeating type names over and over again quickly becomes a problem if the name of the type ever changes, or a refactored is required. It also makes it more difficult to copy code from one method to another.
Solution
In
impl
s,Self
can be used instead of the struct/enum being implemented, to reduce unnecessary repetition. This PR usesSelf
as often as possible. This fixes theuse_self
clippy lint.