@@ -72,7 +72,7 @@ impl DeclarativeMacroExpander {
7272 } ) ;
7373 match self . mac . err ( ) {
7474 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 } ) ,
7676 ExpandError :: other ( format ! ( "invalid macro definition: {e}" ) ) ,
7777 ) ,
7878 None => self
@@ -108,7 +108,7 @@ impl DeclarativeMacroExpander {
108108 } ) ;
109109 match self . mac . err ( ) {
110110 Some ( e) => ExpandResult :: new (
111- tt:: Subtree :: empty ( tt:: DelimSpan :: DUMMY ) ,
111+ tt:: Subtree :: empty ( tt:: DelimSpan { open : call_site , close : call_site } ) ,
112112 ExpandError :: other ( format ! ( "invalid macro definition: {e}" ) ) ,
113113 ) ,
114114 None => self . mac . expand ( & tt, |_| ( ) , new_meta_vars, call_site) . map_err ( Into :: into) ,
@@ -244,12 +244,13 @@ pub fn expand_speculative(
244244
245245 // Build the subtree and token mapping for the speculative args
246246 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+ ) ,
250251 MacroCallKind :: Derive { .. } | MacroCallKind :: Attr { .. } => {
251252 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 ) ;
253254 fixups. append . retain ( |it, _| match it {
254255 syntax:: NodeOrToken :: Node ( it) => !censor. contains ( it) ,
255256 syntax:: NodeOrToken :: Token ( _) => true ,
@@ -261,6 +262,7 @@ pub fn expand_speculative(
261262 span_map,
262263 fixups. append ,
263264 fixups. remove ,
265+ loc. call_site ,
264266 ) ,
265267 fixups. undo_info ,
266268 )
@@ -282,8 +284,9 @@ pub fn expand_speculative(
282284 } ?;
283285 match attr. token_tree ( ) {
284286 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 ) ;
287290
288291 Some ( tree)
289292 }
@@ -297,7 +300,7 @@ pub fn expand_speculative(
297300 // Otherwise the expand query will fetch the non speculative attribute args and pass those instead.
298301 let mut speculative_expansion = match loc. def . kind {
299302 MacroDefKind :: ProcMacro ( expander, ..) => {
300- tt. delimiter = tt:: Delimiter :: DUMMY_INVISIBLE ;
303+ tt. delimiter = tt:: Delimiter :: invisible_spanned ( loc . call_site ) ;
301304 let call_site = loc. span ( db) ;
302305 expander. expand (
303306 db,
@@ -473,12 +476,13 @@ fn macro_arg(
473476 MacroCallKind :: Attr { ast_id, .. } => ast_id. to_ptr ( db) . to_node ( & root) . syntax ( ) . clone ( ) ,
474477 } ;
475478 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+ ) ,
479483 MacroCallKind :: Derive { .. } | MacroCallKind :: Attr { .. } => {
480484 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 ) ;
482486 fixups. append . retain ( |it, _| match it {
483487 syntax:: NodeOrToken :: Node ( it) => !censor. contains ( it) ,
484488 syntax:: NodeOrToken :: Token ( _) => true ,
@@ -490,6 +494,7 @@ fn macro_arg(
490494 map. as_ref ( ) ,
491495 fixups. append . clone ( ) ,
492496 fixups. remove . clone ( ) ,
497+ loc. call_site ,
493498 ) ;
494499 reverse_fixups ( & mut tt, & fixups. undo_info ) ;
495500 }
@@ -499,6 +504,7 @@ fn macro_arg(
499504 map,
500505 fixups. append ,
501506 fixups. remove ,
507+ loc. call_site ,
502508 ) ,
503509 fixups. undo_info ,
504510 )
@@ -507,7 +513,7 @@ fn macro_arg(
507513
508514 if loc. def . is_proc_macro ( ) {
509515 // 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 ;
511517 }
512518
513519 if matches ! ( loc. def. kind, MacroDefKind :: BuiltInEager ( ..) ) {
@@ -611,7 +617,11 @@ fn decl_macro_expander(
611617 ast:: Macro :: MacroRules ( macro_rules) => (
612618 match macro_rules. token_tree ( ) {
613619 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+ ) ;
615625 let mac = mbe:: DeclarativeMacro :: parse_macro_rules ( & tt, is_2021, new_meta_vars) ;
616626 mac
617627 }
@@ -625,7 +635,11 @@ fn decl_macro_expander(
625635 ast:: Macro :: MacroDef ( macro_def) => (
626636 match macro_def. body ( ) {
627637 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+ ) ;
629643 let mac = mbe:: DeclarativeMacro :: parse_macro2 ( & tt, is_2021, new_meta_vars) ;
630644 mac
631645 }
@@ -677,7 +691,7 @@ fn macro_expand(
677691 let Some ( ( macro_arg, undo_info) ) = value else {
678692 return ExpandResult {
679693 value : Arc :: new ( tt:: Subtree {
680- delimiter : tt:: Delimiter :: DUMMY_INVISIBLE ,
694+ delimiter : tt:: Delimiter :: invisible_spanned ( loc . call_site ) ,
681695 token_trees : Vec :: new ( ) ,
682696 } ) ,
683697 // FIXME: We should make sure to enforce an invariant that invalid macro
@@ -736,7 +750,7 @@ fn macro_expand(
736750 // Skip checking token tree limit for include! macro call
737751 if !loc. def . is_include ( ) {
738752 // 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 ) {
740754 return value;
741755 }
742756 }
@@ -749,7 +763,7 @@ fn expand_proc_macro(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<A
749763 let Some ( ( macro_arg, undo_info) ) = db. macro_arg ( id) . value else {
750764 return ExpandResult {
751765 value : Arc :: new ( tt:: Subtree {
752- delimiter : tt:: Delimiter :: DUMMY_INVISIBLE ,
766+ delimiter : tt:: Delimiter :: invisible_spanned ( loc . call_site ) ,
753767 token_trees : Vec :: new ( ) ,
754768 } ) ,
755769 // 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
783797 ) ;
784798
785799 // 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 ) {
787801 return value;
788802 }
789803
@@ -806,12 +820,12 @@ fn token_tree_to_syntax_node(
806820 mbe:: token_tree_to_syntax_node ( tt, entry_point)
807821}
808822
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 > > > {
810824 let count = tt. count ( ) ;
811825 if TOKEN_LIMIT . check ( count) . is_err ( ) {
812826 Err ( ExpandResult {
813827 value : Arc :: new ( tt:: Subtree {
814- delimiter : tt:: Delimiter :: DUMMY_INVISIBLE ,
828+ delimiter : tt:: Delimiter :: invisible_spanned ( call_site ) ,
815829 token_trees : vec ! [ ] ,
816830 } ) ,
817831 err : Some ( ExpandError :: other ( format ! (
0 commit comments