-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
>=
typo gives unclear error message
#98128
Comments
This is complicated, given that macro_rules! foo {
($a:expr => $b:expr) => {};
} |
If this is possible, it would also be nice to mention closures there, since |
Write help for unexpected `=>`. Fixes rust-lang#98128 rust-lang#98128 discusses what to do with the typo `=>` vs `>=`, or efforts to write a JavaScript-syntax closure in Rust (`(a, b) => (a + b)`). Both manifest as an unexpected `token::FatArrow` so the error message describes both. I think that only those who are very new to programming would actually need to be told how to spell `>=`, but I could understand someone misreading the existing error message and not realising what they'd typed. The opposite of this is: ``` (a, b) =< (a + b); ^ expected one of `>` or `as` ``` which I think would be significantly more complex to detect because `=<` isn't a token, and less beneficial as I'm not aware of a language which actually uses that syntax for something.
Output on
|
Given the following code:
The current output is:
playground
This had me very confused for a surprising amount of time. It would be nice if the compiler would give a suggestion to replace
=>
with>=
. In my opinion, this would help a lot for someone typing quickly, and would make it clear that the symbols were in reverse. It might also lead to some false positives, but I think it would still be nice to have.The error is actually worse for macros:
The current output for this macro is:
My suggestion it to simply add a
help
section to both of the above errors, which would suggest replacing the=>
token with>=
.The text was updated successfully, but these errors were encountered: