Skip to content

Confusing error message when not having a variable name #73750

Closed
@AZanellato

Description

@AZanellato

I had a weird error message on the rust compiler when trying to compile something like this:

let Struct { name: "a".to_string() }

Here is a playground link that reproduces it better.

This gives out a weird expected ',' error, which wasn't at all what I was expecting. Certainly because of my sleepy state, but still weird.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
C-bugCategory: This is a bug.
D-confusingDiagnostics: Confusing error or lint that should be reworked.
D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Jun 26, 2020
added
A-parserArea: The lexing & parsing of Rust source code to an AST
and removed
C-bugCategory: This is a bug.
D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
on Jul 4, 2020
added
C-enhancementCategory: An issue proposing an enhancement or a PR with one.
on Jul 5, 2020
estebank

estebank commented on Jul 6, 2020

@estebank
Contributor

Btw, the parser was expecting a comma because let doesn't just take identifiers, but patterns, which let's you write let Struct { name, ..} = struct_val;.

Would the following have been enough to help you?

error: expected `,`
  --> src/main.rs:10:13
   |
 9 |     let Test {
   |         ---- while parsing this pattern
10 |       name: "a".to_owned()
   |             ^^^
AZanellato

AZanellato commented on Jul 6, 2020

@AZanellato
Author

I discovered this shortly thereafter! I think that would happen a ton. Maybe something along the lines of "Maybe you missed a name"?

But that would be awesome already 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.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

        Participants

        @estebank@JohnTitor@AZanellato@LeSeulArtichaut

        Issue actions

          Confusing error message when not having a variable name · Issue #73750 · rust-lang/rust