proc_macro: preserve file module spans for inner attrs#158046
proc_macro: preserve file module spans for inner attrs#158046Dnreikronos wants to merge 1 commit into
Conversation
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
|
r? @mu001999 rustbot has assigned @mu001999. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
|
@rustbot reroll |
|
Could someone review the PR? The fix seems sensible, and works for me. |
|
@rustbot reroll |
This comment has been minimized.
This comment has been minimized.
9633953 to
8a1f71e
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Hi, @nikomatsakis! Best wishes, |
|
r? @Urgau |
|
@rustbot ready |
| } | ||
|
|
||
| fn lex_token_trees_for_span(psess: &ParseSess, span: Span) -> Option<TokenStream> { | ||
| if span.is_dummy() { |
There was a problem hiding this comment.
I'd rather remove this to simplify code, I don't think we need optimizations here.
There was a problem hiding this comment.
Yeah, makes sense. I removed the explicit is_dummy() check and let span_to_snippet handle unavailable spans.
|
|
||
| let mut body_tts = Vec::new(); | ||
| body_tts.extend( | ||
| lex_token_trees_for_span(psess, spans.inner_span.until(attr.span))?.iter().cloned(), |
There was a problem hiding this comment.
Nit: the .iter().cloned() part can be hidden into lex_token_trees_for_span, which can return impl Iterator.
There was a problem hiding this comment.
Done. lex_token_trees_for_span returns an iterator now, so callers don't need .iter().cloned() anymore.
|
r=me after addressing the remaining nits and squashing commits. |
|
Reminder, once the PR becomes ready for a review, use |
46fdb65 to
daff591
Compare
|
@rustbot ready |
View all comments
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.