-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Detect enums with cfg controlled variants that aren't non_exhaustive #9607
Comments
Should an analogous lint exist for structs and enum variants too? |
@pali6 Yes, I think so, if they have public fields that are cfg-gated, and don't have any private fields. |
I've tried experimenting with implementing the lint but sadly reached a dead end. Per Zulip discussion I'll post some of my observations here: Variants with the same nameIn order to make sure that there is a variant not present in all configuration combinations we need to also detect cases where two or more variants with the same name have pub enum E {
V1,
#[cfg(feature = "foo")]
V2(u32),
#[not(feature = "foo")]
V2(u64),
} Due to existence of It might or might not be a good idea to also suppress the lint when the whole enum has Exported itemsThis was not mentioned in the issue but presumably this lint should only trigger when the enum is exported similarly to how other Where to find
|
You're right, this should only apply to
I think it'd be completely reasonable to just handle the simple cases: if there are multiple variants with the same name, either just don't emit the warning (and people are no worse off than they are now), or throw it at a SAT solver but give up if it's too complex. |
What it does
If an enum has variants controlled by cfg (e.g. feature flags), it should almost certainly be non_exhaustive. This lint would flag exhaustive enums controlled by cfg.
This should not flag enums with cfg variants that nonetheless have the same variants in all cfgs.
Lint Name
cfg_enum_exhaustive
Category
suspicious
Advantage
Drawbacks
Possible false positives.
Example
Could be written as:
The text was updated successfully, but these errors were encountered: