Skip to content

fix(parser): emit targeted diagnostic for fields inside traits - #162103

Open
raushan728 wants to merge 2 commits into
rust-lang:mainfrom
raushan728:issues/161815
Open

fix(parser): emit targeted diagnostic for fields inside traits#162103
raushan728 wants to merge 2 commits into
rust-lang:mainfrom
raushan728:issues/161815

Conversation

@raushan728

@raushan728 raushan728 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #161815

Detect ident: Type or self: Type inside trait bodies to emit a clearer diagnostic.

@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 1, 2026
@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, parser
  • compiler, parser expanded to 75 candidates
  • Random selection from 18 candidates

@davidtwco davidtwco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small test change then I'll approve

View changes since this review

fn main() {}

trait Trait1 {
field_name: String, //~ ERROR fields are not allowed in trait definitions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests for cases without a trailing comma?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @davidtwco please take a second look.

Detect `ident: Type` or `self: Type` inside trait bodies to emit a clearer diagnostics.
@raushan728

Copy link
Copy Markdown
Contributor Author

Small test change then I'll approve

View changes since this review

Here it feels like you are telling me to do less testing work.

@raushan728
raushan728 requested a review from davidtwco September 5, 2026 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing diagnostic when trying to define a field in a trait

3 participants