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

Parser finds nonexistent tokens after unclosed delimiters #86073

Open
FabianWolff opened this issue Jun 6, 2021 · 1 comment
Open

Parser finds nonexistent tokens after unclosed delimiters #86073

FabianWolff opened this issue Jun 6, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@FabianWolff
Copy link
Contributor

Whenever there is an unclosed delimiter in the input, the parser tries to recover by inserting the expected closing delimiter somewhere. However, this leads to spurious error messages if another error occurs after recovering, e.g.:

#[i=i::
error: this file contains an unclosed delimiter
 --> test1.rs:1:8
  |
1 | #[i=i::
  |  -     ^
  |  |
  |  unclosed delimiter

error: expected identifier, found `]`
 --> test1.rs:1:8
  |
1 | #[i=i::
  |        ^ expected identifier

error: aborting due to 2 previous errors

or:

impl X { fn foo
error: this file contains an unclosed delimiter
 --> test2.rs:1:16
  |
1 | impl X { fn foo
  |        -       ^
  |        |
  |        unclosed delimiter

error: expected one of `(` or `<`, found `}`
 --> test2.rs:1:16
  |
1 | impl X { fn foo
  |        -       ^
  |        |       |
  |        |       expected one of `(` or `<`
  |        |       the item list ends here
  |        while parsing this item list starting here

i.e. the error messages say that certain tokens were found that clearly aren't present in the input. I can understand why this happens, but I think it is confusing, and that artificially inserted tokens should not appear in error messages like this.

@FabianWolff FabianWolff 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 Jun 6, 2021
@jonas-schievink jonas-schievink added A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. labels Jun 6, 2021
@estebank
Copy link
Contributor

estebank commented Jun 7, 2021

This is somewhat a consequence of turning the TokenSequence into a TokenTree. I would love it if we could treat this better.

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 A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants