Skip to content

Confusing error message for Foo{ bar @ .. } pattern #74701

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
rodrimati1992 opened this issue Jul 23, 2020 · 2 comments · Fixed by #130725
Closed

Confusing error message for Foo{ bar @ .. } pattern #74701

rodrimati1992 opened this issue Jul 23, 2020 · 2 comments · Fixed by #130725
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST A-patterns Relating to patterns and pattern matching C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@rodrimati1992
Copy link
Contributor

rodrimati1992 commented Jul 23, 2020

This erroneous code:

let std::ops::Range{ bar @ .. } = 0..0;

Produces this error message

error: expected `,`
 --> src/main.rs:2:26
  |
2 |     let std::ops::Range{ bar @ .. } = 0..0;
  |                          ^^^

It would be better if instead it produced an error message like this:

error: `bar @` is not allowed in a struct
 --> src/main.rs:2:26
  |
2 |     let std::ops::Range{ bar @ .. } = 0..0;
  |                          ^^^
  = help: remove this and bind each struct field independently
help: if you don't need to use the contents of bar, discard the struct's remaining fields
   |
11 |     let std::ops::Range{ .. } = 0..0;
   |                          ^^

Meta

Tried the code in these Rust versions and they all produced the same error message:

  • 1.37.0 stable

  • 1.45.0 stable

  • 1.46.0-beta.1 (2020-07-15 e51b714)

  • 1.47.0-nightly (2020-07-22 bbebe73)

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-patterns Relating to patterns and pattern matching C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 23, 2020
@rodrimati1992 rodrimati1992 changed the title Confusing error message for Foo{ bar @ .. } Confusing error message for Foo{ bar @ .. } pattern Jul 24, 2020
@estebank estebank added the A-parser Area: The lexing & parsing of Rust source code to an AST label Jul 24, 2020
@JohnTitor JohnTitor added D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Oct 23, 2020
@Nadrieril Nadrieril added the E-help-wanted Call for participation: Help is requested to fix this issue. label Dec 1, 2023
@Nadrieril
Copy link
Member

This shouldn't be too hard. This comes from the parser, specifically the code that parses a pattern, which is one of these parse_pat_* functions. Somewhere there is the code to parse a struct pattern. I assume the error above happens when it successfully parses a struct field and then expects a comma or closing brace. To fix it you'd have to check for @ .. and report a better error message.

@Nadrieril Nadrieril added the E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. label Dec 1, 2023
@GrigorenkoPV
Copy link
Contributor

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST A-patterns Relating to patterns and pattern matching C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. 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.

6 participants