Skip to content

Add a lint warning on bare PatIdent arms #19824

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

Closed
Manishearth opened this issue Dec 13, 2014 · 1 comment
Closed

Add a lint warning on bare PatIdent arms #19824

Manishearth opened this issue Dec 13, 2014 · 1 comment

Comments

@Manishearth
Copy link
Member

At the moment, if an enum variant changes name, match arms containing it silently become wildcard matches. For example, the following:

enum Foo {
 Bar,
 Baz,
 Quux
}
match f {
 Bar => ...,
 Baz => ...
 Quux => ...
}

will silently have the second arm becoming a wildcard arm if the original enum is changed (instead of a compile error which usually is how you can track down uses of a renamed identifier). In some cases we may get an "unreachable pattern" error, but not always.

I'm proposing we add a lint to warn against arms which are a single identifier bound to a variable instead of a variant. Instead, we suggest that _ @ variable arms are used.

This doesn't handle patterns where enums are nested, i.e Some(Bar) when Bar gets renamed. If we want to catch these too we might want to instead lint uppercase PatIdents anywhere in a match where the corresponding type is an enum.

It's pretty easy to write these lints, but I'm not sure if Rust is currently accepting more internal plugins or if this lint is something we really want, hence this issue first.

@Manishearth
Copy link
Member Author

Looks like snake_case already lints these. I guess this isn't necessary then.

lnicola pushed a commit to lnicola/rust that referenced this issue May 26, 2025
fix: Fix cache problems with lints level
lnicola pushed a commit to lnicola/rust that referenced this issue May 28, 2025
fix: Fix cache problems with lints level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant