-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 about overlapping patterns #5657
Comments
We do report useless patterns (those that cannot match because a prior |
The unreachable pattern warning is good, but I'm imagining something that would warn any time the sets of things matched by each pattern were not disjoint. The point of the warning would be to say, "Be advised: the order in which these match arms are written is relevant!" On the other hand, maybe this isn't right for Rust because we often write a catch-all |
Ah, I see! Well, you could make it default to off. Or perhaps we could somehow treat |
Having it default to off sounds like the right thing. |
far-future |
I don't think that GHC warns about the order of match arms being relevant? Certainly ML compilers don't. |
What GHC does is warn about a set of patterns being overlapping -- The idea is that if you have a set of patterns such that in one order you'd get an unreachable pattern warning in Rust, but in a different order you wouldn't, then that code is not robust to reordering. Sometimes this is fine, but other times you might want to at least get a warning that the code is fragile. |
Triage: no progess that I know of. |
previous_comment.clone() |
|
This would have to be a lint, since it's not strictly undesirable behavior. Perhaps this should be closed in favor of an issue on clippy since we're not adding new lints? |
Since new lints have a big impact on users of rustc, the policy is that they should go through the RFC process like other user-facing changes. As such, I'm going to give this one a close, but if anyone comes across this ticket and wants this lint, consider adding it to clippy and/or writing up an RFC. Thanks! |
We already check pattern matches for non-exhaustiveness. It would be nice to also produce a warning for overlapping match patterns ("over-exhaustiveness"). GHC, for example, does this.
The text was updated successfully, but these errors were encountered: