Improve error message: No rules expected the token 'a' #49370
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Let's say you are a beginner to Rust and you forget a comma while using
println!
. (This could happen to anyone, but let's specifically imagine that you do not know the language and its features well.)Here is the error you would get:
Since you're a beginner, it is likely that macros are going to be one of the last features you touch. So "no rules expected the token" would not make any sense to you.
Now let's look at what happens if you forget a comma in a regular function:
Here is the error that you get:
This is much better because it makes it clear that we forgot one of the options presented and it is pretty obvious how to fix it.
Since we know exactly which tokens a macro expects, wouldn't it be possible to generate a similar looking (or different but informative) message for macros too? I think this would really enhance the experience especially for beginners who may not understand "no rules expected the token" errors in macros.
Please pardon me if this is a duplicate. I reported this because when I encountered it, I was confused for a second. If I can get confused by this error message after 3 years of programming in Rust, a beginner is certainly likely to be stumped for much longer. It would be awesome if this could improve! 😄
The text was updated successfully, but these errors were encountered: