Skip to content

Attributes following a missing trailing comma produce over-eager recovery #100461

@saethlin

Description

@saethlin
Member

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8a65ac81b182494a4856b59164bffbc2

struct Feelings {
    owo: bool
    #[allow(unused)] // If commented-out, we recover differently and do not get the additional error about no field `owo`
    uwu: bool,
}

impl Feelings {
    fn hmm(&self) -> bool {
        self.owo
    }
}

Having an attribute after the field with missing , turns the error from this (which is good):

   Compiling playground v0.0.1 (/playground)
error: expected `,`, or `}`, found `uwu`
 --> src/main.rs:2:14
  |
2 |     owo: bool
  |              ^ help: try adding a comma: `,`

error: could not compile `playground` due to previous error

To this, which contains unhelpful errors and possibly a huge number of them on a larger codebase:

Compiling playground v0.0.1 (/playground)
error: expected `,`, or `}`, found `#`
 --> src/main.rs:2:14
  |
2 |     owo: bool
  |              ^

error[E0609]: no field `owo` on type `&Feelings`
 --> src/main.rs:9:14
  |
9 |         self.owo
  |              ^^^ unknown field

For more information about this error, try `rustc --explain E0609`.
error: could not compile `playground` due to 2 previous errors

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Aug 12, 2022
chenyukang

chenyukang commented on Aug 13, 2022

@chenyukang
Member

@rustbot claim

added a commit that references this issue on Aug 13, 2022
29f905b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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

    Participants

    @chenyukang@saethlin

    Issue actions

      Attributes following a missing trailing comma produce over-eager recovery · Issue #100461 · rust-lang/rust