Skip to content

proc_macro: preserve file module spans for inner attrs#158046

Open
Dnreikronos wants to merge 3 commits into
rust-lang:mainfrom
Dnreikronos:proc_macro/file_mod_inner_attr_spans
Open

proc_macro: preserve file module spans for inner attrs#158046
Dnreikronos wants to merge 3 commits into
rust-lang:mainfrom
Dnreikronos:proc_macro/file_mod_inner_attr_spans

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

fixes #157881

out-of-line mods with custom inner attrs were sending proc macros a pretty-printed module wrapper. the awkward bit: tokens inside the module picked up the span from the parent mod foo;, so later diags pointed at the decl instead of the file where the code actually came from.

this keeps the wrapper synthetic, but puts the loaded file body back into the token stream with its own spans. it also skips the attr currently being expanded, so we don't replay it by accident. added a small ui repro too, plus the older span-debug output changed because those spans are now real.

imo this is the least annoying fix for now. fwiw, it keeps the old fake-wrapper path instead of trying to make full token capture for file mods happen in this PR.

@rustbot

rustbot commented Jun 17, 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 Jun 17, 2026
@rustbot

rustbot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
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 73 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@mu001999

Copy link
Copy Markdown
Member

@rustbot reroll

@zjp-CN

zjp-CN commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Could someone review the PR? The fix seems sensible, and works for me.

@mati865

mati865 commented Jun 19, 2026

Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned nikomatsakis and unassigned mati865 Jun 19, 2026
Comment thread compiler/rustc_parse/src/lib.rs
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.

Custom inner attribute on file modules has bad diagnostics

8 participants