@@ -35,7 +35,7 @@ pub struct DeclarativeMacroExpander {
35
35
}
36
36
37
37
impl DeclarativeMacroExpander {
38
- pub fn expand ( & self , tt : & tt:: Subtree ) -> ExpandResult < tt:: Subtree > {
38
+ pub fn expand ( & self , tt : tt:: Subtree ) -> ExpandResult < tt:: Subtree > {
39
39
match self . mac . err ( ) {
40
40
Some ( e) => ExpandResult :: new (
41
41
tt:: Subtree :: empty ( ) ,
@@ -44,6 +44,14 @@ impl DeclarativeMacroExpander {
44
44
None => self . mac . expand ( tt) . map_err ( Into :: into) ,
45
45
}
46
46
}
47
+
48
+ pub fn map_id_down ( & self , token_id : tt:: TokenId ) -> tt:: TokenId {
49
+ self . mac . map_id_down ( token_id)
50
+ }
51
+
52
+ pub fn map_id_up ( & self , token_id : tt:: TokenId ) -> ( tt:: TokenId , mbe:: Origin ) {
53
+ self . mac . map_id_up ( token_id)
54
+ }
47
55
}
48
56
49
57
#[ derive( Debug , Clone , Eq , PartialEq ) ]
@@ -61,10 +69,11 @@ pub enum TokenExpander {
61
69
ProcMacro ( ProcMacroExpander ) ,
62
70
}
63
71
72
+ // FIXME: Get rid of these methods
64
73
impl TokenExpander {
65
74
pub ( crate ) fn map_id_down ( & self , id : tt:: TokenId ) -> tt:: TokenId {
66
75
match self {
67
- TokenExpander :: DeclarativeMacro ( expander) => expander. mac . map_id_down ( id) ,
76
+ TokenExpander :: DeclarativeMacro ( expander) => expander. map_id_down ( id) ,
68
77
TokenExpander :: BuiltIn ( ..)
69
78
| TokenExpander :: BuiltInEager ( ..)
70
79
| TokenExpander :: BuiltInAttr ( ..)
@@ -75,7 +84,7 @@ impl TokenExpander {
75
84
76
85
pub ( crate ) fn map_id_up ( & self , id : tt:: TokenId ) -> ( tt:: TokenId , mbe:: Origin ) {
77
86
match self {
78
- TokenExpander :: DeclarativeMacro ( expander) => expander. mac . map_id_up ( id) ,
87
+ TokenExpander :: DeclarativeMacro ( expander) => expander. map_id_up ( id) ,
79
88
TokenExpander :: BuiltIn ( ..)
80
89
| TokenExpander :: BuiltInEager ( ..)
81
90
| TokenExpander :: BuiltInAttr ( ..)
@@ -167,7 +176,6 @@ pub fn expand_speculative(
167
176
token_to_map : SyntaxToken ,
168
177
) -> Option < ( SyntaxNode , SyntaxToken ) > {
169
178
let loc = db. lookup_intern_macro_call ( actual_macro_call) ;
170
- let macro_def = db. macro_def ( loc. def ) ;
171
179
let token_range = token_to_map. text_range ( ) ;
172
180
173
181
// Build the subtree and token mapping for the speculative args
@@ -225,7 +233,12 @@ pub fn expand_speculative(
225
233
None => {
226
234
let range = token_range. checked_sub ( speculative_args. text_range ( ) . start ( ) ) ?;
227
235
let token_id = spec_args_tmap. token_by_range ( range) ?;
228
- macro_def. map_id_down ( token_id)
236
+ match loc. def . kind {
237
+ MacroDefKind :: Declarative ( it) => {
238
+ db. decl_macro_expander ( loc. krate , it) . map_id_down ( token_id)
239
+ }
240
+ _ => token_id,
241
+ }
229
242
}
230
243
} ;
231
244
@@ -244,7 +257,7 @@ pub fn expand_speculative(
244
257
let adt = ast:: Adt :: cast ( speculative_args. clone ( ) ) . unwrap ( ) ;
245
258
expander. expand ( db, actual_macro_call, & adt, & spec_args_tmap)
246
259
}
247
- MacroDefKind :: Declarative ( it) => db. decl_macro_expander ( loc. krate , it) . expand ( & tt) ,
260
+ MacroDefKind :: Declarative ( it) => db. decl_macro_expander ( loc. krate , it) . expand ( tt) ,
248
261
MacroDefKind :: BuiltIn ( it, _) => it. expand ( db, actual_macro_call, & tt) . map_err ( Into :: into) ,
249
262
MacroDefKind :: BuiltInEager ( it, _) => {
250
263
it. expand ( db, actual_macro_call, & tt) . map_err ( Into :: into)
@@ -518,7 +531,7 @@ fn macro_expand(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<Arc<tt
518
531
let ( arg, arg_tm, undo_info) = & * macro_arg;
519
532
let mut res = match loc. def . kind {
520
533
MacroDefKind :: Declarative ( id) => {
521
- db. decl_macro_expander ( loc. def . krate , id) . expand ( & arg)
534
+ db. decl_macro_expander ( loc. def . krate , id) . expand ( arg. clone ( ) )
522
535
}
523
536
MacroDefKind :: BuiltIn ( it, _) => it. expand ( db, id, & arg) . map_err ( Into :: into) ,
524
537
MacroDefKind :: BuiltInEager ( it, _) => it. expand ( db, id, & arg) . map_err ( Into :: into) ,
0 commit comments