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 and T: &Trait #106694

Closed
estebank opened this issue Jan 10, 2023 · 1 comment · Fixed by #106712
Closed

Recover from impl &Trait and T: &Trait #106694

estebank opened this issue Jan 10, 2023 · 1 comment · Fixed by #106712
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. 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 Jan 10, 2023

The following two function definitions are not valid:

fn foo(_: impl &Trait) {}
fn bar<T: &Trait>(_: T) {}

They fail in the parser and it doesn't recover nicely.

error: expected one of `:`, `@`, or `|`, found `)`
 --> src/main.rs:2:22
  |
2 | fn foo(_: impl &Trait) {}
  |                      ^ expected one of `:`, `@`, or `|`
  |
  = note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a parameter name, give it a type
  |
2 | fn foo(_: impl Trait: &TypeName) {}
  |                ~~~~~~~~~~~~~~~~
help: if this is a type, explicitly ignore the parameter name
  |
2 | fn foo(_: impl _: &Trait) {}
  |                ++

error: expected one of `!`, `(`, `)`, `,`, `?`, `for`, `~`, lifetime, or path, found `&`
 --> src/main.rs:2:16
  |
2 | fn foo(_: impl &Trait) {}
  |               -^ expected one of 9 possible tokens
  |               |
  |               help: missing `,`

error: expected one of `!`, `(`, `,`, `=`, `>`, `?`, `for`, `~`, lifetime, or path, found `&`
 --> src/main.rs:3:11
  |
3 | fn bar<T: &Trait>(_: T) {}
  |           ^ expected one of 10 possible tokens

It should produce an appropriate error message, closer to the output for impl &Trait for () {}:

error: expected a trait, found type
 --> src/main.rs:2:6
  |
2 | impl &Trait for () {}
  |      ^^^^^^
@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-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Jan 10, 2023
@Ezrashaw
Copy link
Contributor

@rustbot claim

Might take a while, it is P-low after all.

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-verbose Diagnostics: Too much output caused by a single piece of incorrect code. 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