@@ -143,7 +143,11 @@ impl HirFileId {
143
143
let loc: MacroCallLoc = db. lookup_intern_macro ( lazy_id) ;
144
144
145
145
let arg_tt = loc. kind . arg ( db) ?;
146
- let def_tt = loc. def . ast_id ?. to_node ( db) . token_tree ( ) ?;
146
+
147
+ let def = loc. def . ast_id . and_then ( |id| {
148
+ let def_tt = id. to_node ( db) . token_tree ( ) ?;
149
+ Some ( InFile :: new ( id. file_id , def_tt) )
150
+ } ) ;
147
151
148
152
let macro_def = db. macro_def ( loc. def ) ?;
149
153
let ( parse, exp_map) = db. parse_macro_expansion ( macro_file) . value ?;
@@ -152,7 +156,7 @@ impl HirFileId {
152
156
Some ( ExpansionInfo {
153
157
expanded : InFile :: new ( self , parse. syntax_node ( ) ) ,
154
158
arg : InFile :: new ( loc. kind . file_id ( ) , arg_tt) ,
155
- def : InFile :: new ( loc . def . ast_id ? . file_id , def_tt ) ,
159
+ def,
156
160
macro_arg,
157
161
macro_def,
158
162
exp_map,
@@ -311,7 +315,8 @@ pub struct EagerCallLoc {
311
315
pub struct ExpansionInfo {
312
316
expanded : InFile < SyntaxNode > ,
313
317
arg : InFile < SyntaxNode > ,
314
- def : InFile < ast:: TokenTree > ,
318
+ /// The `macro_rules!` arguments.
319
+ def : Option < InFile < ast:: TokenTree > > ,
315
320
316
321
macro_def : Arc < ( db:: TokenExpander , mbe:: TokenMap ) > ,
317
322
macro_arg : Arc < ( tt:: Subtree , mbe:: TokenMap ) > ,
@@ -348,9 +353,14 @@ impl ExpansionInfo {
348
353
let ( token_id, origin) = self . macro_def . 0 . map_id_up ( token_id) ;
349
354
let ( token_map, tt) = match origin {
350
355
mbe:: Origin :: Call => ( & self . macro_arg . 1 , self . arg . clone ( ) ) ,
351
- mbe:: Origin :: Def => {
352
- ( & self . macro_def . 1 , self . def . as_ref ( ) . map ( |tt| tt. syntax ( ) . clone ( ) ) )
353
- }
356
+ mbe:: Origin :: Def => (
357
+ & self . macro_def . 1 ,
358
+ self . def
359
+ . as_ref ( )
360
+ . expect ( "`Origin::Def` used with non-`macro_rules!` macro" )
361
+ . as_ref ( )
362
+ . map ( |tt| tt. syntax ( ) . clone ( ) ) ,
363
+ ) ,
354
364
} ;
355
365
356
366
let range = token_map. range_by_token ( token_id) ?. by_kind ( token. value . kind ( ) ) ?;
0 commit comments