@@ -313,16 +313,18 @@ fn parse_macro_expansion(
313313let loc = db. lookup_intern_macro_call ( macro_file. macro_call_id ) ;
314314let edition = loc. def . edition ;
315315let expand_to = loc. expand_to ( ) ;
316- let mbe:: ValueResult { value : tt, err } = macro_expand ( db, macro_file. macro_call_id , loc) ;
316+ let mbe:: ValueResult { value : ( tt, matched_arm) , err } =
317+ macro_expand ( db, macro_file. macro_call_id , loc) ;
317318
318- let ( parse, rev_token_map) = token_tree_to_syntax_node (
319+ let ( parse, mut rev_token_map) = token_tree_to_syntax_node (
319320match & tt {
320321CowArc :: Arc ( it) => it,
321322CowArc :: Owned ( it) => it,
322323} ,
323324 expand_to,
324325 edition,
325326) ;
327+ rev_token_map. matched_arm = matched_arm;
326328
327329ExpandResult { value : ( parse, Arc :: new ( rev_token_map) ) , err }
328330}
@@ -544,11 +546,13 @@ fn macro_expand(
544546db : & dyn ExpandDatabase ,
545547macro_call_id : MacroCallId ,
546548loc : MacroCallLoc ,
547- ) -> ExpandResult < CowArc < tt:: Subtree > > {
549+ ) -> ExpandResult < ( CowArc < tt:: Subtree > , Option < u32 > ) > {
548550let _p = tracing:: span!( tracing:: Level :: INFO , "macro_expand" ) . entered ( ) ;
549551
550- let ( ExpandResult { value : tt, err } , span) = match loc. def . kind {
551- MacroDefKind :: ProcMacro ( ..) => return db. expand_proc_macro ( macro_call_id) . map ( CowArc :: Arc ) ,
552+ let ( ExpandResult { value : ( tt, matched_arm) , err } , span) = match loc. def . kind {
553+ MacroDefKind :: ProcMacro ( ..) => {
554+ return db. expand_proc_macro ( macro_call_id) . map ( CowArc :: Arc ) . zip_val ( None )
555+ }
552556 _ => {
553557let ( macro_arg, undo_info, span) =
554558 db. macro_arg_considering_derives ( macro_call_id, & loc. kind ) ;
@@ -560,10 +564,10 @@ fn macro_expand(
560564. decl_macro_expander ( loc. def . krate , id)
561565. expand ( db, arg. clone ( ) , macro_call_id, span) ,
562566MacroDefKind :: BuiltIn ( it, _) => {
563- it. expand ( db, macro_call_id, arg, span) . map_err ( Into :: into)
567+ it. expand ( db, macro_call_id, arg, span) . map_err ( Into :: into) . zip_val ( None )
564568}
565569MacroDefKind :: BuiltInDerive ( it, _) => {
566- it. expand ( db, macro_call_id, arg, span) . map_err ( Into :: into)
570+ it. expand ( db, macro_call_id, arg, span) . map_err ( Into :: into) . zip_val ( None )
567571}
568572MacroDefKind :: BuiltInEager ( it, _) => {
569573// This might look a bit odd, but we do not expand the inputs to eager macros here.
@@ -574,7 +578,8 @@ fn macro_expand(
574578// As such we just return the input subtree here.
575579let eager = match & loc. kind {
576580MacroCallKind :: FnLike { eager : None , .. } => {
577- return ExpandResult :: ok ( CowArc :: Arc ( macro_arg. clone ( ) ) ) ;
581+ return ExpandResult :: ok ( CowArc :: Arc ( macro_arg. clone ( ) ) )
582+ . zip_val ( None ) ;
578583}
579584MacroCallKind :: FnLike { eager : Some ( eager) , .. } => Some ( & * * eager) ,
580585 _ => None ,
@@ -586,12 +591,12 @@ fn macro_expand(
586591// FIXME: We should report both errors!
587592 res. err = error. clone ( ) . or ( res. err ) ;
588593}
589- res
594+ res. zip_val ( None )
590595}
591596MacroDefKind :: BuiltInAttr ( it, _) => {
592597let mut res = it. expand ( db, macro_call_id, arg, span) ;
593598 fixup:: reverse_fixups ( & mut res. value , & undo_info) ;
594- res
599+ res. zip_val ( None )
595600}
596601 _ => unreachable ! ( ) ,
597602} ;
@@ -603,16 +608,18 @@ fn macro_expand(
603608if !loc. def . is_include ( ) {
604609// Set a hard limit for the expanded tt
605610if let Err ( value) = check_tt_count ( & tt) {
606- return value. map ( |( ) | {
607- CowArc :: Owned ( tt:: Subtree {
608- delimiter : tt:: Delimiter :: invisible_spanned ( span) ,
609- token_trees : Box :: new ( [ ] ) ,
611+ return value
612+ . map ( |( ) | {
613+ CowArc :: Owned ( tt:: Subtree {
614+ delimiter : tt:: Delimiter :: invisible_spanned ( span) ,
615+ token_trees : Box :: new ( [ ] ) ,
616+ } )
610617} )
611- } ) ;
618+ . zip_val ( matched_arm ) ;
612619}
613620}
614621
615- ExpandResult { value : CowArc :: Owned ( tt) , err }
622+ ExpandResult { value : ( CowArc :: Owned ( tt) , matched_arm ) , err }
616623}
617624
618625fn proc_macro_span ( db : & dyn ExpandDatabase , ast : AstId < ast:: Fn > ) -> Span {
0 commit comments