-
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
WIP: Add `not_exhaustive_enough´ lint #6328
Conversation
/// E::Third => {} | ||
/// } |
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 point of #[non_exhaustive]
is that the wildcard match is always required:
/// E::Third => {} | |
/// } | |
/// E::Third => {} | |
/// _ => {} | |
/// } |
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 the effort you've put into this!
I did a first round of review, don't hesitate to ask for clarification if needed.
Also, my apologies for the delay in reviewing, I did not have much free time lately. |
I'm slightly concerned that the full use of this lint will be held back by inability to distinguish between:
match io_error.kind() {
ErrorKind::TimedOut => self.retry(),
_ => return Err(io_error), // This is intended to match all known and unknown kinds.
} if let Some(Foo { x, .. /* don't care for the rest */ }) = maybe_foo {
..
} These issues can always be ignored case-by-case with I don't really have any good solutions to this problem and I do feel having the lint as it is implemented here is better than not having it at all. :) |
Thank you for the review! I will make the necessary changes as soon as possible |
@Rantanen that's a very good point. The idea behind the lint is to warn in case new fields/variants are added, so it should target those cases where the user wanted to be as exhaustive as possible. But we don't know how the data structure looked like when the user wrote the code, so we can only approximate. Some possible heuristics could be (although I'm not happy with any of them TBH):
|
If the lint turns out to be more annoying than helpful we can always turn it into a |
☔ The latest upstream changes (presumably #6389) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
ping from triage @jrqc. There seem to be some small fixes left to be done. Could you have any update on this? |
Sorry about the delayed response @ebroto @giraffate |
@ebroto Made the necessary changes! Hope I didn't miss anything |
Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
Co-authored-by: Eduardo Broto <ebroto@tutanota.com>
31a5752
to
891d914
Compare
No problem, thanks for sticking with it! I will try to review in the coming days. |
r? @Manishearth (I'm leaving the team, so I'm reassigning my PRs to other active members) |
I'll review this when I get a chance, but I'm wondering: we're replicating a lot of the exhaustiveness checking logic in rustc, yeah? Can we use it, or make this lint a lint in rustc? |
@flip1995 what are your opinions on the above^ ? |
I don't really have an opinion on this, since I didn't review any of the exhaustiveness PRs AFAICR. I just can give a general answer: If we can share code with rustc, we should do that. But I don't know how code in Clippy or rustc looks like for exhaustiveness checks. |
@flip1995 so the thing is that rustc already has exhaustiveness checks, and this is a lint that was proposed in a Rust RFC, so it would both be easy to implement in rustc and make sense. It feels weird to reimplement exhaustiveness checking in a partial way outside of rustc when we can have a perfect version of this lint in rustc. |
Yeah, agreed. |
ping from triage @Manishearth. Do we still need discussion here? |
Yeah, sorry, I think we've discussed this and we shouldn't be doing this in clippy. It's worth filing a bug on rust-lang/rust to add such an allow-default lint. Sorry @jrqc! |
I can't find an issue about this lint at rust-lang/rust, did anybody end up creating one? Also, given that this won't be implemented in clippy, somebody should close the associated issue (#5557). |
r? @ebroto
Fixes #5557
changelog: new lint
not_exhaustive_enough