proc_macro: Fix cfg_attr inner attrs in file modules#159695
Conversation
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
|
r? @nnethercote rustbot has assigned @nnethercote. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
1aff8cc to
6cdda28
Compare
|
cc// @mejrs |
|
At this point collecting the tokens properly would probably be simpler. For an easy solution, I'd suggest removing |
Done. I removed |
|
(I meant reverting all the other changes besides this one.) |
sry, I misunderstood or request! |
Done, I reverted everything except the lexer failure fallback you suggested. The PR diff now only removes |
|
This seems fine. @bors r+ rollup
FWIW, I'm working on a PR to change |
…le_mod_inner_attr, r=nnethercote proc_macro: Fix cfg_attr inner attrs in file modules Fixes rust-lang#159648 Inner proc-macro attrs produced by `cfg_attr` only carry the nested attr span. Splitting source around that span tries to lex two unmatched halves, so file modules fail with an unclosed delimiter. Lex the complete module body first, then remove the expanded attr from its nested token stream. Sibling attrs stay in place, and empty `cfg_attr` wrappers use their trace span and disappear. imo this is cleaner than teaching source slicing about every nested shape. Tests exercise sibling attrs on either side of the proc macro, then cover the single-attr case. fyi, denied lints make sibling preservation observable; ltm if another nested case should live here.
|
@Dnreikronos |
|
This pull request was unapproved. This PR was contained in a rollup (#159879), which was unapproved. |
Return to pretty-printed token reconstruction when lexing source slices around an inner attribute produces unmatched delimiters. Cover cfg_attr-expanded proc-macro attributes in an out-of-line module, including sibling attributes on both sides.
60dac3d to
1f8b15f
Compare
|
@bors r=nnethercote,petrochenkov |
Fixes #159648
Inner proc-macro attrs produced by
cfg_attronly carry the nested attr span. Splitting source around that span tries to lex two unmatched halves, so file modules fail with an unclosed delimiter.Lex the complete module body first, then remove the expanded attr from its nested token stream. Sibling attrs stay in place, and empty
cfg_attrwrappers use their trace span and disappear. imo this is cleaner than teaching source slicing about every nested shape.Tests exercise sibling attrs on either side of the proc macro, then cover the single-attr case. fyi, denied lints make sibling preservation observable; ltm if another nested case should live here.