Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

GKFX
Copy link
Contributor

@GKFX GKFX commented Jun 18, 2022

#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.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 18, 2022
@rust-highfive
Copy link
Collaborator

r? @jackh726

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 18, 2022
@rust-log-analyzer

This comment has been minimized.

@Dylan-DPC
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 19, 2022

📌 Commit 04f9957 has been approved by Dylan-DPC

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 19, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 19, 2022
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.
@jackh726
Copy link
Member

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 19, 2022
@jackh726
Copy link
Member

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.

@jackh726
Copy link
Member

@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.

@GKFX
Copy link
Contributor Author

GKFX commented Jul 12, 2022

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 1 => 2 and something like (a, b) => {...; a + b}.

@JohnCSimon
Copy link
Member

@GKFX
ping from triage - can you post your status on this PR? Thanks
FYI: when a PR is ready for review, send a message containing
@rustbot ready to switch to S-waiting-on-review so the PR is in the reviewer's backlog.

@GKFX
Copy link
Contributor Author

GKFX commented Aug 13, 2022

I added the requested test but am still not sure how to avoid the false positive in code like src/test/ui/missing/missing-comma-in-match.stderr (as seen in the diff).

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 2, 2022
@jackh726
Copy link
Member

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

@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 1, 2023
@Dylan-DPC
Copy link
Member

@GKFX any updates on this?

@JohnCSimon
Copy link
Member

@GKFX
Ping from triage: I'm closing this due to inactivity, Please reopen when you are ready to continue with this.
Note: if you are going to continue please open the PR BEFORE you push to it, else you won't be able to reopen - this is a quirk of github.
Thanks for your contribution.

@rustbot label: +S-inactive

@JohnCSimon JohnCSimon closed this May 28, 2023
@rustbot rustbot added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label May 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants