-
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
New lint: warn about missing variants/fields for non-exhaustive enums/structs #5557
Comments
I've updated the description with some details to make it clearer. |
Hi, is this issue already resolved? If so, it would be better to close this. |
Nope, this issue is still relevant |
I'd like to give this issue a shot |
Added a new lint called |
This issue should be closed and move to rustic rust-lang/rust#84332? |
Yes this should be implemented in rustc and is tracked in the issue you linked. Thanks for noticing! |
As suggested in the non_exhaustive RFC, when using non-exhaustive enums and structs in patterns, the lint would warn the user for missing variants or fields despite having a wildcard arm or a rest pattern.
This can be useful when new fields/variants are added by the upstream crate so that they don't go unnoticed.
Enums
Given the following definition
The following use should be linted:
Structs
Given the following definition
The following cases should be linted
In addition to let destructuring in function parameters
A struct variant of an enum should be linted in the same cases if it's the only variant of the enum. If it's not the only member, it can be linted only in the match, if let and while let cases.
Tuple structs
Tuple structs can't be used in patterns if there are private fields using the
T()
syntax, but theT{0: _, 1: _}
syntax can be used an so it should be linted like with structs.Given the following definition
The following cases should be linted
In addition to let destructuring in function parameters
Notes
The text was updated successfully, but these errors were encountered: