@@ -10,7 +10,7 @@ use either::Either;
1010use limit:: Limit ;
1111use mbe:: { syntax_node_to_token_tree, ValueResult } ;
1212use rustc_hash:: FxHashSet ;
13- use span:: SyntaxContextId ;
13+ use span:: { Span , SyntaxContextId } ;
1414use syntax:: {
1515 ast:: { self , HasAttrs } ,
1616 AstNode , Parse , SyntaxError , SyntaxNode , SyntaxToken , T ,
@@ -57,7 +57,8 @@ impl DeclarativeMacroExpander {
5757 tt : tt:: Subtree ,
5858 call_id : MacroCallId ,
5959 ) -> ExpandResult < tt:: Subtree > {
60- let toolchain = & db. crate_graph ( ) [ db. lookup_intern_macro_call ( call_id) . def . krate ] . toolchain ;
60+ let loc = db. lookup_intern_macro_call ( call_id) ;
61+ let toolchain = & db. crate_graph ( ) [ loc. def . krate ] . toolchain ;
6162 let new_meta_vars = toolchain. as_ref ( ) . map_or ( false , |version| {
6263 REQUIREMENT . get_or_init ( || VersionReq :: parse ( ">=1.76" ) . unwrap ( ) ) . matches (
6364 & base_db:: Version {
@@ -80,6 +81,7 @@ impl DeclarativeMacroExpander {
8081 & tt,
8182 |s| s. ctx = apply_mark ( db, s. ctx , call_id, self . transparency ) ,
8283 new_meta_vars,
84+ loc. call_site ,
8385 )
8486 . map_err ( Into :: into) ,
8587 }
@@ -90,6 +92,7 @@ impl DeclarativeMacroExpander {
9092 db : & dyn ExpandDatabase ,
9193 tt : tt:: Subtree ,
9294 krate : CrateId ,
95+ call_site : Span ,
9396 ) -> ExpandResult < tt:: Subtree > {
9497 let toolchain = & db. crate_graph ( ) [ krate] . toolchain ;
9598 let new_meta_vars = toolchain. as_ref ( ) . map_or ( false , |version| {
@@ -108,7 +111,7 @@ impl DeclarativeMacroExpander {
108111 tt:: Subtree :: empty ( tt:: DelimSpan :: DUMMY ) ,
109112 ExpandError :: other ( format ! ( "invalid macro definition: {e}" ) ) ,
110113 ) ,
111- None => self . mac . expand ( & tt, |_| ( ) , new_meta_vars) . map_err ( Into :: into) ,
114+ None => self . mac . expand ( & tt, |_| ( ) , new_meta_vars, call_site ) . map_err ( Into :: into) ,
112115 }
113116 }
114117}
@@ -315,9 +318,12 @@ pub fn expand_speculative(
315318 let adt = ast:: Adt :: cast ( speculative_args. clone ( ) ) . unwrap ( ) ;
316319 expander. expand ( db, actual_macro_call, & adt, span_map)
317320 }
318- MacroDefKind :: Declarative ( it) => {
319- db. decl_macro_expander ( loc. krate , it) . expand_unhygienic ( db, tt, loc. def . krate )
320- }
321+ MacroDefKind :: Declarative ( it) => db. decl_macro_expander ( loc. krate , it) . expand_unhygienic (
322+ db,
323+ tt,
324+ loc. def . krate ,
325+ loc. call_site ,
326+ ) ,
321327 MacroDefKind :: BuiltIn ( it, _) => it. expand ( db, actual_macro_call, & tt) . map_err ( Into :: into) ,
322328 MacroDefKind :: BuiltInEager ( it, _) => {
323329 it. expand ( db, actual_macro_call, & tt) . map_err ( Into :: into)
0 commit comments