Skip to content

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

Closed
@rodrimati1992

Description

@rodrimati1992

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)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTA-patternsRelating to patterns and pattern matchingC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.E-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions