@@ -72,7 +72,7 @@ impl DeclarativeMacroExpander {
72
72
} ) ;
73
73
match self . mac . err ( ) {
74
74
Some ( e) => ExpandResult :: new (
75
- tt:: Subtree :: empty ( tt:: DelimSpan :: DUMMY ) ,
75
+ tt:: Subtree :: empty ( tt:: DelimSpan { open : loc . call_site , close : loc . call_site } ) ,
76
76
ExpandError :: other ( format ! ( "invalid macro definition: {e}" ) ) ,
77
77
) ,
78
78
None => self
@@ -108,7 +108,7 @@ impl DeclarativeMacroExpander {
108
108
} ) ;
109
109
match self . mac . err ( ) {
110
110
Some ( e) => ExpandResult :: new (
111
- tt:: Subtree :: empty ( tt:: DelimSpan :: DUMMY ) ,
111
+ tt:: Subtree :: empty ( tt:: DelimSpan { open : call_site , close : call_site } ) ,
112
112
ExpandError :: other ( format ! ( "invalid macro definition: {e}" ) ) ,
113
113
) ,
114
114
None => self . mac . expand ( & tt, |_| ( ) , new_meta_vars, call_site) . map_err ( Into :: into) ,
@@ -244,12 +244,13 @@ pub fn expand_speculative(
244
244
245
245
// Build the subtree and token mapping for the speculative args
246
246
let ( mut tt, undo_info) = match loc. kind {
247
- MacroCallKind :: FnLike { .. } => {
248
- ( mbe:: syntax_node_to_token_tree ( speculative_args, span_map) , SyntaxFixupUndoInfo :: NONE )
249
- }
247
+ MacroCallKind :: FnLike { .. } => (
248
+ mbe:: syntax_node_to_token_tree ( speculative_args, span_map, loc. call_site ) ,
249
+ SyntaxFixupUndoInfo :: NONE ,
250
+ ) ,
250
251
MacroCallKind :: Derive { .. } | MacroCallKind :: Attr { .. } => {
251
252
let censor = censor_for_macro_input ( & loc, speculative_args) ;
252
- let mut fixups = fixup:: fixup_syntax ( span_map, speculative_args) ;
253
+ let mut fixups = fixup:: fixup_syntax ( span_map, speculative_args, loc . call_site ) ;
253
254
fixups. append . retain ( |it, _| match it {
254
255
syntax:: NodeOrToken :: Node ( it) => !censor. contains ( it) ,
255
256
syntax:: NodeOrToken :: Token ( _) => true ,
@@ -261,6 +262,7 @@ pub fn expand_speculative(
261
262
span_map,
262
263
fixups. append ,
263
264
fixups. remove ,
265
+ loc. call_site ,
264
266
) ,
265
267
fixups. undo_info ,
266
268
)
@@ -282,8 +284,9 @@ pub fn expand_speculative(
282
284
} ?;
283
285
match attr. token_tree ( ) {
284
286
Some ( token_tree) => {
285
- let mut tree = syntax_node_to_token_tree ( token_tree. syntax ( ) , span_map) ;
286
- tree. delimiter = tt:: Delimiter :: DUMMY_INVISIBLE ;
287
+ let mut tree =
288
+ syntax_node_to_token_tree ( token_tree. syntax ( ) , span_map, loc. call_site ) ;
289
+ tree. delimiter = tt:: Delimiter :: invisible_spanned ( loc. call_site ) ;
287
290
288
291
Some ( tree)
289
292
}
@@ -297,7 +300,7 @@ pub fn expand_speculative(
297
300
// Otherwise the expand query will fetch the non speculative attribute args and pass those instead.
298
301
let mut speculative_expansion = match loc. def . kind {
299
302
MacroDefKind :: ProcMacro ( expander, ..) => {
300
- tt. delimiter = tt:: Delimiter :: DUMMY_INVISIBLE ;
303
+ tt. delimiter = tt:: Delimiter :: invisible_spanned ( loc . call_site ) ;
301
304
let call_site = loc. span ( db) ;
302
305
expander. expand (
303
306
db,
@@ -473,12 +476,13 @@ fn macro_arg(
473
476
MacroCallKind :: Attr { ast_id, .. } => ast_id. to_ptr ( db) . to_node ( & root) . syntax ( ) . clone ( ) ,
474
477
} ;
475
478
let ( mut tt, undo_info) = match loc. kind {
476
- MacroCallKind :: FnLike { .. } => {
477
- ( mbe:: syntax_node_to_token_tree ( & syntax, map. as_ref ( ) ) , SyntaxFixupUndoInfo :: NONE )
478
- }
479
+ MacroCallKind :: FnLike { .. } => (
480
+ mbe:: syntax_node_to_token_tree ( & syntax, map. as_ref ( ) , loc. call_site ) ,
481
+ SyntaxFixupUndoInfo :: NONE ,
482
+ ) ,
479
483
MacroCallKind :: Derive { .. } | MacroCallKind :: Attr { .. } => {
480
484
let censor = censor_for_macro_input ( & loc, & syntax) ;
481
- let mut fixups = fixup:: fixup_syntax ( map. as_ref ( ) , & syntax) ;
485
+ let mut fixups = fixup:: fixup_syntax ( map. as_ref ( ) , & syntax, loc . call_site ) ;
482
486
fixups. append . retain ( |it, _| match it {
483
487
syntax:: NodeOrToken :: Node ( it) => !censor. contains ( it) ,
484
488
syntax:: NodeOrToken :: Token ( _) => true ,
@@ -490,6 +494,7 @@ fn macro_arg(
490
494
map. as_ref ( ) ,
491
495
fixups. append . clone ( ) ,
492
496
fixups. remove . clone ( ) ,
497
+ loc. call_site ,
493
498
) ;
494
499
reverse_fixups ( & mut tt, & fixups. undo_info ) ;
495
500
}
@@ -499,6 +504,7 @@ fn macro_arg(
499
504
map,
500
505
fixups. append ,
501
506
fixups. remove ,
507
+ loc. call_site ,
502
508
) ,
503
509
fixups. undo_info ,
504
510
)
@@ -507,7 +513,7 @@ fn macro_arg(
507
513
508
514
if loc. def . is_proc_macro ( ) {
509
515
// proc macros expect their inputs without parentheses, MBEs expect it with them included
510
- tt. delimiter = tt:: Delimiter :: DUMMY_INVISIBLE ;
516
+ tt. delimiter . kind = tt:: DelimiterKind :: Invisible ;
511
517
}
512
518
513
519
if matches ! ( loc. def. kind, MacroDefKind :: BuiltInEager ( ..) ) {
@@ -611,7 +617,11 @@ fn decl_macro_expander(
611
617
ast:: Macro :: MacroRules ( macro_rules) => (
612
618
match macro_rules. token_tree ( ) {
613
619
Some ( arg) => {
614
- let tt = mbe:: syntax_node_to_token_tree ( arg. syntax ( ) , map. as_ref ( ) ) ;
620
+ let tt = mbe:: syntax_node_to_token_tree (
621
+ arg. syntax ( ) ,
622
+ map. as_ref ( ) ,
623
+ map. span_for_range ( macro_rules. macro_rules_token ( ) . unwrap ( ) . text_range ( ) ) ,
624
+ ) ;
615
625
let mac = mbe:: DeclarativeMacro :: parse_macro_rules ( & tt, is_2021, new_meta_vars) ;
616
626
mac
617
627
}
@@ -625,7 +635,11 @@ fn decl_macro_expander(
625
635
ast:: Macro :: MacroDef ( macro_def) => (
626
636
match macro_def. body ( ) {
627
637
Some ( arg) => {
628
- let tt = mbe:: syntax_node_to_token_tree ( arg. syntax ( ) , map. as_ref ( ) ) ;
638
+ let tt = mbe:: syntax_node_to_token_tree (
639
+ arg. syntax ( ) ,
640
+ map. as_ref ( ) ,
641
+ map. span_for_range ( macro_def. macro_token ( ) . unwrap ( ) . text_range ( ) ) ,
642
+ ) ;
629
643
let mac = mbe:: DeclarativeMacro :: parse_macro2 ( & tt, is_2021, new_meta_vars) ;
630
644
mac
631
645
}
@@ -677,7 +691,7 @@ fn macro_expand(
677
691
let Some ( ( macro_arg, undo_info) ) = value else {
678
692
return ExpandResult {
679
693
value : Arc :: new ( tt:: Subtree {
680
- delimiter : tt:: Delimiter :: DUMMY_INVISIBLE ,
694
+ delimiter : tt:: Delimiter :: invisible_spanned ( loc . call_site ) ,
681
695
token_trees : Vec :: new ( ) ,
682
696
} ) ,
683
697
// FIXME: We should make sure to enforce an invariant that invalid macro
@@ -736,7 +750,7 @@ fn macro_expand(
736
750
// Skip checking token tree limit for include! macro call
737
751
if !loc. def . is_include ( ) {
738
752
// Set a hard limit for the expanded tt
739
- if let Err ( value) = check_tt_count ( & tt) {
753
+ if let Err ( value) = check_tt_count ( & tt, loc . call_site ) {
740
754
return value;
741
755
}
742
756
}
@@ -749,7 +763,7 @@ fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<A
749
763
let Some ( ( macro_arg, undo_info) ) = db. macro_arg ( id) . value else {
750
764
return ExpandResult {
751
765
value : Arc :: new ( tt:: Subtree {
752
- delimiter : tt:: Delimiter :: DUMMY_INVISIBLE ,
766
+ delimiter : tt:: Delimiter :: invisible_spanned ( loc . call_site ) ,
753
767
token_trees : Vec :: new ( ) ,
754
768
} ) ,
755
769
// FIXME: We should make sure to enforce an invariant that invalid macro
@@ -783,7 +797,7 @@ fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<A
783
797
) ;
784
798
785
799
// Set a hard limit for the expanded tt
786
- if let Err ( value) = check_tt_count ( & tt) {
800
+ if let Err ( value) = check_tt_count ( & tt, loc . call_site ) {
787
801
return value;
788
802
}
789
803
@@ -806,12 +820,12 @@ fn token_tree_to_syntax_node(
806
820
mbe:: token_tree_to_syntax_node ( tt, entry_point)
807
821
}
808
822
809
- fn check_tt_count ( tt : & tt:: Subtree ) -> Result < ( ) , ExpandResult < Arc < tt:: Subtree > > > {
823
+ fn check_tt_count ( tt : & tt:: Subtree , call_site : Span ) -> Result < ( ) , ExpandResult < Arc < tt:: Subtree > > > {
810
824
let count = tt. count ( ) ;
811
825
if TOKEN_LIMIT . check ( count) . is_err ( ) {
812
826
Err ( ExpandResult {
813
827
value : Arc :: new ( tt:: Subtree {
814
- delimiter : tt:: Delimiter :: DUMMY_INVISIBLE ,
828
+ delimiter : tt:: Delimiter :: invisible_spanned ( call_site ) ,
815
829
token_trees : vec ! [ ] ,
816
830
} ) ,
817
831
err : Some ( ExpandError :: other ( format ! (
0 commit comments