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

Recover from impl Trait in type param bound #102182

Closed
estebank opened this issue Sep 23, 2022 · 3 comments · Fixed by #102345
Closed

Recover from impl Trait in type param bound #102182

estebank opened this issue Sep 23, 2022 · 3 comments · Fixed by #102345
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST D-papercut Diagnostics: An error or lint that needs small tweaks. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Sep 23, 2022

When writing fn foo<T: impl Trait>() {} the current error is "expected one of these tokens", without any attempt to recover the parse. It should instead be closer to:

error[E0404]: expected trait, found struct `S`
 --> src/lib.rs:2:11
  |
2 | fn foo<T: S>() {}
  |           ^ not a trait
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Sep 23, 2022
@chenyukang
Copy link
Member

What do you expect the suggestion from this code?

error: expected one of `(`, `+`, `,`, `::`, `<`, `=`, or `>`, found `test`
 --> bug2.rs:3:17
  |
3 | fn foo<T: hello test>() {}
  |                 ^^^^ expected one of 7 possible tokens

error: aborting due to previous error

here hello is a valid identifier, "expected one of these tokens" comes when the second identifier comes.

@estebank
Copy link
Contributor Author

I think this case should remain as is. impl Trait in particular is a shame because it is a valid type for the parser, but not a valid trait, and newcomers might not yet have a mental model for the distinction. I would say, when parsing a trait, if it can't be parsed, then try to parse a type in a snapshot (like we do in other parts of the parser), and if successful, emit a targeted error (trait expected but found {descr} type).

@chenyukang
Copy link
Member

@rustbot claim

JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 10, 2022
…r=estebank

Recover from impl Trait in type param bound

Fixes rust-lang#102182
r? `@estebank`
JohnTitor added a commit to JohnTitor/rust that referenced this issue Oct 10, 2022
…r=estebank

Recover from impl Trait in type param bound

Fixes rust-lang#102182
r? ``@estebank``
@bors bors closed this as completed in 7b2f04a Oct 10, 2022
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 D-papercut Diagnostics: An error or lint that needs small tweaks. P-low Low priority 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.

2 participants