-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Lint for use of operator's trait's method instead of the operator itself #6286
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
Comments
I would try to implement this 🙃. But I have some questions beforehand if you don't mind:
This is a collected list of all traits in
Excluded from the lint:
|
|
The operator was wrong thank you @NieDzejkob for pointing that point. I agree that you might want to use I've updated my comment with the correct operator and the |
I believe that this issue needs some more discussion before it can be completely implemented/introduced. This conversation has already shown that some users could prefer I even see a use case for the opposite, i.e. saying: "I want to disallow the use of the Proposal:We implement a lint like The lint additionally includes several configurations to enable the users to set up the lint to their liking:
I believe that this proposal would cover all uncases and give the use the most freedom. However, it also feels a bit different to me than other lints because everything is configurable. 1. This is a placeholder name, and it open for suggestions. It's hard to follow the naming conventions as this proposal suggest covering both sides of the lint (disallowing methods in favor of the operator and the other way around). 2. Also, a placeholder name suggestions are welcome. @rustbot label +C-needs-discussion |
What it does
If somebody calls
std::ops::Add::add(foo, bar)
, suggestfoo + bar
.In my experience with Exercism, beginners often find the API they need in the trait, not realizing its relation to the operator. Naming the trait method requires an import and is usually unnecessarily verbose, so we might want to lint against it.
Categories
clippy::style
Drawbacks
None.
Example
Could be written as:
Note
This is a follow-up to #5679, which described a similar issue for
FromIterator
, and the case of operator traits got mentioned in the comments. The PR that solved theFromIterator
case didn't handle this case, so i'm opening a separate issue.The text was updated successfully, but these errors were encountered: