-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Matching field-less enum variants that aren't imported should deny-lint, not just give lots of warnings #103442
Comments
If you look at the warnings, they explain what is happening
This issue can be closed as Not A Bug |
Ah yes, didn't consider that, sorry. I'm used to getting errors in such cases because matching more complex variants like this will usually fail. |
A case of "Warning Blindness"? |
I think this is a case where we should have a specific lint that we can make deny-by-default. The generic ones are good, but it would be nice to have one for "I see what happened here, and you definitely didn't want this" that can block compilation (by default -- it could be Specifically, I'm thinking a lint that looks for a pattern with a match-all binding whose name is the same as one of the variants of the enum. It can suggest changing the pattern from See https://rustc-dev-guide.rust-lang.org/diagnostics.html for how to make a lint, if anyone is interested in picking this up! (Perhaps it should also support |
@rustbot claim |
@rustbot claim |
@scottmcm how would that lint be different from |
Oh, thanks @est31 ! If it already exists that's even better -- just a matter of making it deny-by-default. (Want to send a PR for that, timrobertsdev ?) |
I got the same problem recently (#104966) ... :) I totally agree with this proposal! |
@scottmcm you're welcome :). It's interesting that I was the first person to point that out after your comment: many people have probably seen it, and seen the warning output in the comment posted by @aDotInTheVoid where |
…ings_with_variant_name, r=scottmcm Change `bindings_with_variant_name` to deny-by-default Changed the `bindings_with_variant_name` lint to deny-by-default and fixed up the affected tests. Addresses rust-lang#103442.
…ings_with_variant_name, r=scottmcm Change `bindings_with_variant_name` to deny-by-default Changed the `bindings_with_variant_name` lint to deny-by-default and fixed up the affected tests. Addresses rust-lang#103442.
When the enum variants listed in a
match
block omit the precedingEnumName::
the compiler may still accept the code, even if some cases were not handled or nonexistent variants are listed.I tried this code:
I expected to see this happen: Compiler errors regarding missing
Enum::
, missing variantEnum::C
, and invalid variant.Instead, this happened: the code compiled and printed "A"
Meta
rustc --version --verbose
:Also tested with
rustc 1.66.0-nightly (f83e0266c 2022-10-03)
The text was updated successfully, but these errors were encountered: