-
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
Warn by default when encountering a statement which only consists of an equality comparison #1812
Conversation
/cc @rust-lang/compiler @rust-lang/lang |
Good idea, 👍 from me. |
This is a special case of " |
So with that method, This lint could be added in the meantime, and perhaps removed when the must_use solution is implemented. Although I admit that would be wasted effort. |
@crumblingstatue unfortunately once added a lint cannot be removed, because that would break code that has (for example) |
Oh, I see. In that case, #886 should be carefully reconsidered before merging this RFC. I'll add it to the alternatives. |
``` | ||
|
||
However, not everyone uses clippy, and I believe this is a common enough mistake | ||
to justify including a lint for it in rustc itself. |
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.
isn't the solution to simply move the lint from clippy to rustc? Together with the unnecessary_operation
lint for maximal effect
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.
The no_effect
lint in clippy has a larger scope than this one, making it more prone to false positives, and less likely to be accepted into rustc. But I'll add merging this lint into rustc as a possible alternative.
Since unnecessary_operation
is not required to solve the problem described in the motivation, it should probably belong in a separate RFC.
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.
an intermediate solution is to name the rustc lint no_effect
, only implement your suggested a == b;
check, and thus ensure that the lint's name will never become obsolete, since it can be extended to more complex situations.
What are false positives of (At the moment, there is no open issues for |
@sanxiyn |
IIRC no_effect is a conservative lint -- If anything, it has false negatives, but not false positives. |
I really like the Annotating |
Team member @aturon has proposed to close this. The next step is review by the rest of the tagged teams:
No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I would advise against closing this until an RFC proposing an alternative solution is actually merged. This RFC has a clearly stated motivation, and also summarizes the alternatives, so it's a good fallback point if #886 isn't actually merged. |
I'm in favor of 886 over this RFC. The previous RFC was closed for lack of strong motivation, and this RFC has found that motivation. A general mechanism seems better than a one-off lint. @crumblingstatue If the conversation on 886 turns against we can re-open this RFC and consider it in light of that. |
@withoutboats Not everyone can reopen issues. If you promise to reopen when the situation arises, sure. |
@crumblingstatue @sanxiyn Worth considering the significance of an open PR & who can open and close PRs. From a purely technical standpoint, anyone can open a new PR with an identical diff; there are no real controls on what outstanding PRs exist against this repo. But in terms of what becomes implemented in rustc, the reality is that decisions are not made on the basis of the existence of an open PR, but through the social process that happens on these threads. Open PRs & merged RFCs are just a mechanism for organizing and tracking that discussion. The only reason this PR wouldn't be re-opened is if the outcome of the discussion on #886 is that in addition to not wanting So Aaron's proposing that we would be more likely to merge #886 than #1812, and since they are for the same purpose we should move discussion over there. Keeping this RFC open would just make it more likely for discussion to bifurcate into two threads, making it harder to reach a shared position (in that sense, my re-opening of #886 today may have been premature). |
Thanks @withoutboats, that's basically how I see things as well. I don't think re-opening #886 is premature, though we will need someone to take over the RFC. It's also not uncommon to have multiple RFCs open on the same topic; usually we try to go into FCP at the same time on such RFCs. I think we should try to move quickly on #886. |
Given that the entirety of the lang team has signed off on moving to FCP for closure (and lints are generally lang team purview), I'm going to manually move to FCP. This RFC is entering its final comment period, with disposition to close, in favor of pursuing #886. |
Closing this. |
Although RFC 1940 is about annotating functions with `#[must_use]`, a key part of the motivation was linting unused equality operators. (See https://github.com/rust-lang/rfcs/pull/1812#issuecomment-265695898—it seems to have not been clear to discussants at the time that marking the comparison methods as `must_use` would not give us the lints on comparison operators, at least in (what the present author understood as) the most straightforward implementation, as landed in rust-lang#43728 (3645b06).) To rectify the situation, we here lint unused comparison operators as part of the unused-must-use lint (feature gated by the `fn_must_use` feature flag, which now arguably becomes a slight (tolerable in the opinion of the present author) misnomer). This is in the matter of rust-lang#43302.
add comparison operators to must-use lint (under `fn_must_use` feature) Although RFC 1940 is about annotating functions with `#[must_use]`, a key part of the motivation was linting unused equality operators. (See https://github.com/rust-lang/rfcs/pull/1812#issuecomment-265695898—it seems to have not been clear to discussants at the time that marking the comparison methods as `must_use` would not give us the lints on comparison operators, at least in (what the present author understood as) the most straightforward implementation, as landed in rust-lang#43728 (3645b06).) To rectify the situation, we here lint unused comparison operators as part of the unused-must-use lint (feature gated by the `fn_must_use` feature flag, which now arguably becomes a slight (tolerable in the opinion of the present author) misnomer). This is in the matter of rust-lang#43302. cc @crumblingstatue
Rendered