Skip to content

Recover inner attributes in algebraic data types - #162018

Open
JonathanBrouwer wants to merge 2 commits into
rust-lang:mainfrom
JonathanBrouwer:attr_empty_struct
Open

Recover inner attributes in algebraic data types#162018
JonathanBrouwer wants to merge 2 commits into
rust-lang:mainfrom
JonathanBrouwer:attr_empty_struct

Conversation

@JonathanBrouwer

Copy link
Copy Markdown
Member

Previously, if you'd put an inner attribute in an empty ADT, such as a struct:

struct Test1 {
    #![inline]
}

You'd get the following errors

error: an inner attribute is not permitted in this context
 --> src/lib.rs:5:5
  |
5 |     #![cfg(false)]
  |     ^^^^^^^^^^^^^^
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
  = note: outer attributes, like `#[test]`, annotate the item following them

error: expected identifier, found `}`
 --> src/lib.rs:6:1
  |
4 | struct Test3 {
  |        ----- while parsing this struct
5 |     #![cfg(false)]
6 | }
  | ^ expected identifier

error: could not compile `rust-test` (lib) due to 2 previous errors

The second error is spurious. It was caused by us only recovering inner attributes just before parsing a field, meaning if we see an inner attribute and recover we expect a field next. This PR fixes that by recovering inner attributes just after the curly brace as well.

@rustbot

rustbot commented Aug 30, 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 Aug 30, 2026
@rustbot

rustbot commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

r? @wesleywiser

rustbot has assigned @wesleywiser.
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
  • compiler expanded to 75 candidates
  • Random selection from 19 candidates

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.

3 participants