@@ -120,7 +120,7 @@ pub trait ExpandDatabase: SourceDatabase {
120
120
fn macro_arg (
121
121
& self ,
122
122
id : MacroCallId ,
123
- ) -> Arc < ( tt:: Subtree , mbe:: TokenMap , fixup:: SyntaxFixupUndoInfo ) > ;
123
+ ) -> Option < Arc < ( tt:: Subtree , mbe:: TokenMap , fixup:: SyntaxFixupUndoInfo ) > > ;
124
124
/// Extracts syntax node, corresponding to a macro call. That's a firewall
125
125
/// query, only typing in the macro call itself changes the returned
126
126
/// subtree.
@@ -318,17 +318,8 @@ fn parse_macro_expansion(
318
318
fn macro_arg (
319
319
db : & dyn ExpandDatabase ,
320
320
id : MacroCallId ,
321
- ) -> Arc < ( tt:: Subtree , mbe:: TokenMap , fixup:: SyntaxFixupUndoInfo ) > {
322
- let Some ( arg) = db. macro_arg_text ( id) else {
323
- return Arc :: new ( (
324
- tt:: Subtree {
325
- delimiter : tt:: Delimiter :: UNSPECIFIED ,
326
- token_trees : Vec :: new ( ) ,
327
- } ,
328
- Default :: default ( ) ,
329
- Default :: default ( ) )
330
- ) ;
331
- } ;
321
+ ) -> Option < Arc < ( tt:: Subtree , mbe:: TokenMap , fixup:: SyntaxFixupUndoInfo ) > > {
322
+ let arg = db. macro_arg_text ( id) ?;
332
323
let loc = db. lookup_intern_macro_call ( id) ;
333
324
334
325
let node = SyntaxNode :: new_root ( arg) ;
@@ -347,7 +338,7 @@ fn macro_arg(
347
338
// proc macros expect their inputs without parentheses, MBEs expect it with them included
348
339
tt. delimiter = tt:: Delimiter :: unspecified ( ) ;
349
340
}
350
- Arc :: new ( ( tt, tmap, fixups. undo_info ) )
341
+ Some ( Arc :: new ( ( tt, tmap, fixups. undo_info ) ) )
351
342
}
352
343
353
344
fn censor_for_macro_input ( loc : & MacroCallLoc , node : & SyntaxNode ) -> FxHashSet < SyntaxNode > {
@@ -472,7 +463,20 @@ fn macro_expand(db: &dyn ExpandDatabase, id: MacroCallId) -> ExpandResult<Arc<tt
472
463
}
473
464
}
474
465
} ;
475
- let macro_arg = db. macro_arg ( id) ;
466
+ let Some ( macro_arg) = db. macro_arg ( id) else {
467
+ return ExpandResult {
468
+ value : Arc :: new (
469
+ tt:: Subtree {
470
+ delimiter : tt:: Delimiter :: UNSPECIFIED ,
471
+ token_trees : Vec :: new ( ) ,
472
+ } ,
473
+ ) ,
474
+ err : Some ( ExpandError :: Other (
475
+ "invalid token tree"
476
+ . into ( ) ,
477
+ ) ) ,
478
+ } ;
479
+ } ;
476
480
let ExpandResult { value : mut tt, err } = expander. expand ( db, id, & macro_arg. 0 ) ;
477
481
// Set a hard limit for the expanded tt
478
482
let count = tt. count ( ) ;
@@ -508,7 +512,18 @@ fn parse_macro_expansion_error(
508
512
509
513
fn expand_proc_macro ( db : & dyn ExpandDatabase , id : MacroCallId ) -> ExpandResult < tt:: Subtree > {
510
514
let loc: MacroCallLoc = db. lookup_intern_macro_call ( id) ;
511
- let macro_arg = db. macro_arg ( id) ;
515
+ let Some ( macro_arg) = db. macro_arg ( id) else {
516
+ return ExpandResult {
517
+ value : tt:: Subtree {
518
+ delimiter : tt:: Delimiter :: UNSPECIFIED ,
519
+ token_trees : Vec :: new ( ) ,
520
+ } ,
521
+ err : Some ( ExpandError :: Other (
522
+ "invalid token tree"
523
+ . into ( ) ,
524
+ ) ) ,
525
+ } ;
526
+ } ;
512
527
513
528
let expander = match loc. def . kind {
514
529
MacroDefKind :: ProcMacro ( expander, ..) => expander,
0 commit comments