@@ -10,7 +10,7 @@ use either::Either;
10
10
use limit:: Limit ;
11
11
use mbe:: { syntax_node_to_token_tree, ValueResult } ;
12
12
use rustc_hash:: FxHashSet ;
13
- use span:: SyntaxContextId ;
13
+ use span:: { Span , SyntaxContextId } ;
14
14
use syntax:: {
15
15
ast:: { self , HasAttrs } ,
16
16
AstNode , Parse , SyntaxError , SyntaxNode , SyntaxToken , T ,
@@ -57,7 +57,8 @@ impl DeclarativeMacroExpander {
57
57
tt : tt:: Subtree ,
58
58
call_id : MacroCallId ,
59
59
) -> 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 ;
61
62
let new_meta_vars = toolchain. as_ref ( ) . map_or ( false , |version| {
62
63
REQUIREMENT . get_or_init ( || VersionReq :: parse ( ">=1.76" ) . unwrap ( ) ) . matches (
63
64
& base_db:: Version {
@@ -80,6 +81,7 @@ impl DeclarativeMacroExpander {
80
81
& tt,
81
82
|s| s. ctx = apply_mark ( db, s. ctx , call_id, self . transparency ) ,
82
83
new_meta_vars,
84
+ loc. call_site ,
83
85
)
84
86
. map_err ( Into :: into) ,
85
87
}
@@ -90,6 +92,7 @@ impl DeclarativeMacroExpander {
90
92
db : & dyn ExpandDatabase ,
91
93
tt : tt:: Subtree ,
92
94
krate : CrateId ,
95
+ call_site : Span ,
93
96
) -> ExpandResult < tt:: Subtree > {
94
97
let toolchain = & db. crate_graph ( ) [ krate] . toolchain ;
95
98
let new_meta_vars = toolchain. as_ref ( ) . map_or ( false , |version| {
@@ -108,7 +111,7 @@ impl DeclarativeMacroExpander {
108
111
tt:: Subtree :: empty ( tt:: DelimSpan :: DUMMY ) ,
109
112
ExpandError :: other ( format ! ( "invalid macro definition: {e}" ) ) ,
110
113
) ,
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) ,
112
115
}
113
116
}
114
117
}
@@ -315,9 +318,12 @@ pub fn expand_speculative(
315
318
let adt = ast:: Adt :: cast ( speculative_args. clone ( ) ) . unwrap ( ) ;
316
319
expander. expand ( db, actual_macro_call, & adt, span_map)
317
320
}
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
+ ) ,
321
327
MacroDefKind :: BuiltIn ( it, _) => it. expand ( db, actual_macro_call, & tt) . map_err ( Into :: into) ,
322
328
MacroDefKind :: BuiltInEager ( it, _) => {
323
329
it. expand ( db, actual_macro_call, & tt) . map_err ( Into :: into)
0 commit comments