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

Suggest joining two identifiers if the grammer is invalid and they would form a keyword #89640

Closed
Noratrieb opened this issue Oct 7, 2021 · 3 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Noratrieb
Copy link
Member

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9adebfa3cae4c99b1fa5c0c9f25e154a

fn main() {
    l et x = 5;
}

The current output is:

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `et`
 --> src/main.rs:2:7
  |
2 |     l et x = 5;
  |       ^^ expected one of 8 possible tokens

Ideally the output should look like:

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `et`
 --> src/main.rs:2:7
  |
2 |     l et x = 5;
  |       ^^ expected one of 8 possible tokens

     hint: did you accidentally put a space inside the keyword `let`?

Sometimes you accidentally insert whitespace inside a keyword, and might not notice it immediately. This minimal case is pretty obvious, but it might not actually always be that obvious if a lot is going on.

This could even be extended to cover all names in scope.

@Noratrieb Noratrieb added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 7, 2021
@camelid
Copy link
Member

camelid commented Jan 25, 2022

Why did you close this issue? I think it's a good idea.

@Noratrieb
Copy link
Member Author

I don't think there's any value to implement it, since the mistake is always obvious, but I can reopen it if you'd like

@camelid
Copy link
Member

camelid commented Jan 26, 2022

I think it's still worthwhile because people can sometimes get confused in the moment, especially if macros are involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants