-
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
Write help for unexpected =>
. Fixes #98128
#98240
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@bors r+ |
📌 Commit 04f9957 has been approved by |
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.
@bors r- |
I'm unconvinced that this should be merged as-is. This may be a useful suggestion, but there needs to be tests added to show that. #98128 has some examples, can you add them as tests? I also think the suggestions where they are now are useful. They're actually confusing. I think this suggestion needs to be special-cased more. |
@GKFX can you address my above comment? Specifically, can you add tests that highlight the usefulness of this change? I'd like to be able to not emit this in the false-positives shown here. If you'd like some help trying to fix that, let me know. If it's too difficult and the usefulness is very clear, I'd probably settle with a FIXME. |
Other than a check for TokenType::Operator, I wasn't sure how best to make it more specific. I can add tests for cases when it is intended to be useful, something containing |
@GKFX |
I added the requested test but am still not sure how to avoid the false positive in code like |
I'm not really familiar with the parsing code, so I'm going to reroll and maybe someone else can advise. r? rust-lang/compiler |
@GKFX any updates on this? |
@GKFX @rustbot label: +S-inactive |
#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 unexpectedtoken::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: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.