@@ -120,7 +120,7 @@ pub trait ExpandDatabase: SourceDatabase {
120120 fn macro_arg (
121121 & self ,
122122 id : MacroCallId ,
123- ) -> Arc < ( tt:: Subtree , mbe:: TokenMap , fixup:: SyntaxFixupUndoInfo ) > ;
123+ ) -> Option < Arc < ( tt:: Subtree , mbe:: TokenMap , fixup:: SyntaxFixupUndoInfo ) > > ;
124124 /// Extracts syntax node, corresponding to a macro call. That's a firewall
125125 /// query, only typing in the macro call itself changes the returned
126126 /// subtree.
@@ -318,17 +318,8 @@ fn parse_macro_expansion(
318318fn macro_arg (
319319 db : & dyn ExpandDatabase ,
320320 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) ?;
332323 let loc = db. lookup_intern_macro_call ( id) ;
333324
334325 let node = SyntaxNode :: new_root ( arg) ;
@@ -347,7 +338,7 @@ fn macro_arg(
347338 // proc macros expect their inputs without parentheses, MBEs expect it with them included
348339 tt. delimiter = tt:: Delimiter :: unspecified ( ) ;
349340 }
350- Arc :: new ( ( tt, tmap, fixups. undo_info ) )
341+ Some ( Arc :: new ( ( tt, tmap, fixups. undo_info ) ) )
351342}
352343
353344fn 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
472463 }
473464 }
474465 } ;
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+ } ;
476480 let ExpandResult { value : mut tt, err } = expander. expand ( db, id, & macro_arg. 0 ) ;
477481 // Set a hard limit for the expanded tt
478482 let count = tt. count ( ) ;
@@ -508,7 +512,18 @@ fn parse_macro_expansion_error(
508512
509513fn expand_proc_macro ( db : & dyn ExpandDatabase , id : MacroCallId ) -> ExpandResult < tt:: Subtree > {
510514 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+ } ;
512527
513528 let expander = match loc. def . kind {
514529 MacroDefKind :: ProcMacro ( expander, ..) => expander,
0 commit comments