Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

crumblingstatue
Copy link

@crumblingstatue crumblingstatue commented Dec 7, 2016

@steveklabnik steveklabnik added T-compiler Relevant to the compiler team, which will review and decide on the RFC. T-lang Relevant to the language team, which will review and decide on the RFC. labels Dec 8, 2016
@steveklabnik
Copy link
Member

/cc @rust-lang/compiler @rust-lang/lang

@aturon
Copy link
Member

aturon commented Dec 8, 2016

Good idea, 👍 from me.

@petrochenkov
Copy link
Contributor

This is a special case of "#[must_use] on functions" - #886.
I'd rather resurrect that RFC rather than add a special purpose lint for one case.

@crumblingstatue
Copy link
Author

This is a special case of "#[must_use] on functions" - #886.
I'd rather resurrect that RFC rather than add a special purpose lint for one case.

So with that method, PartialEq::eq would be marked must_use? I would personally be fine with that solution. This should serve as additional motivation for that RFC.

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.

@withoutboats
Copy link
Contributor

@crumblingstatue unfortunately once added a lint cannot be removed, because that would break code that has (for example) #![deny(eq_statement)].

@crumblingstatue
Copy link
Author

@crumblingstatue unfortunately once added a lint cannot be removed, because that would break code that has (for example) #![deny(eq_statement)].

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.
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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.

@sanxiyn
Copy link
Member

sanxiyn commented Dec 14, 2016

What are false positives of no_effect lint in Clippy? As an initial author of that lint, I'd like to learn them and fix them. Unlike some other lints in Clippy, the lint is intended to be completely free of false positives.

(At the moment, there is no open issues for no_effect lint in Clippy repository.)

@crumblingstatue
Copy link
Author

@sanxiyn
I'm not aware of any false positives either. What I'm stating is that since it's larger in scope than the lint proposed here, it is more likely to potentially have false positives, so it needs to be carefully investigated before merging into rustc.

@Manishearth
Copy link
Member

IIRC no_effect is a conservative lint -- If anything, it has false negatives, but not false positives.

@withoutboats withoutboats self-assigned this Dec 22, 2016
@joshtriplett
Copy link
Member

I really like the #[must_use] approach as well. I feel like #886 got buried under a side issue of "which functions should have #[must_use] annotations", which prevented the underlying change of supporting #[must_use] on functions from going through.

Annotating PartialEq::{eq, ne} and Ord::{lt,le,gt,ge} with #[must_use] would handle this nicely, rather than adding a compiler special-case for the equality operator.

@aturon
Copy link
Member

aturon commented Jan 11, 2017

I'm going to propose we close this RFC in favor of reviving #886, as multiple people have proposed.

@rfcbot fcp close

@rfcbot
Copy link
Collaborator

rfcbot commented Jan 11, 2017

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.

@crumblingstatue
Copy link
Author

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.

@withoutboats
Copy link
Contributor

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.

@sanxiyn
Copy link
Member

sanxiyn commented Jan 12, 2017

@withoutboats Not everyone can reopen issues. If you promise to reopen when the situation arises, sure.

@withoutboats
Copy link
Contributor

@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 #[must_use] on functions, we determine we don't want or cannot support a lint on PartialEq::partial_eq. Such a decision would be reached through discussion on that PR, with an FCP proposal & subsequent FCP period for people to voice disagreement with the decision.

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).

@aturon
Copy link
Member

aturon commented Jan 12, 2017

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.

@aturon
Copy link
Member

aturon commented Feb 1, 2017

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.

@aturon aturon added the final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. label Feb 1, 2017
@withoutboats
Copy link
Contributor

Closing this.

iopq added a commit to iopq/rfcs that referenced this pull request Mar 2, 2017
aturon added a commit that referenced this pull request Jul 17, 2017
Updated RFC #886 with lessons learned from #1812
zackmdavis added a commit to zackmdavis/rust that referenced this pull request Sep 22, 2017
Although RFC 1940 is about annotating functions with `#[must_use]`, a
key part of the motivation was linting unused equality operators.

(See
rust-lang/rfcs#1812 (comment)
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.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 24, 2017
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
rust-lang/rfcs#1812 (comment)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. T-compiler Relevant to the compiler team, which will review and decide on the RFC. T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants