Skip to content

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

Closed
@saethlin

Description

@saethlin

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

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

Development

No branches or pull requests

Issue actions