-
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
Error message when defining enum using struct syntax #103869
Comments
Do you have any suggestion for how the compiler should distinguish between "trying to write an enum with struct syntax" and "trying to write a struct but used the enum keyword"? |
Linking to the topic on internals where some other folks have left suggestions (https://internals.rust-lang.org/t/error-message-when-definining-enum-using-struct-syntax/17669). Although none of those directly address your question. My gut reaction is to assume that if the "enum" keyword is used that truly was the intention of the developer, but if it wasn't, hopefully some help message like the following:
Would provide enough information to trigger an "Oh wait did I really want to use an enum here?" |
@rustbot claim |
propagate the error from parsing enum variant to the parser and emit out While parsing enum variant, the error message always disappear Because the error message that emit out is from main error of parser The information of enum variant disappears while parsing enum variant with error We only check the syntax of expecting token, i.e, in case rust-lang#103869 It will error it without telling the message that this error is from pasring enum variant. Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err Check the sub-error before emitting the main error of parser and attach it. Fix rust-lang#103869
propagate the error from parsing enum variant to the parser and emit out While parsing enum variant, the error message always disappear Because the error message that emit out is from main error of parser The information of enum variant disappears while parsing enum variant with error We only check the syntax of expecting token, i.e, in case rust-lang#103869 It will error it without telling the message that this error is from pasring enum variant. Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err Check the sub-error before emitting the main error of parser and attach it. Fix rust-lang#103869
Although I know Enums take to form of:
I sometimes find myself accidentally defining them as I would a Struct (playground):
The current output is:
This always takes more than a few seconds to parse and then realize my mistake.
Is it possible to change this to something like:
The text was updated successfully, but these errors were encountered: