@@ -3127,6 +3127,10 @@ MacroExpander::expand_decl_macro (Location invoc_locus,
3127
3127
3128
3128
if (did_match_rule)
3129
3129
{
3130
+ for (auto &frag : matched_fragments)
3131
+ rust_debug (" matched fragment: %s" ,
3132
+ frag.second .as_string ().c_str ());
3133
+
3130
3134
matched_rule = &rule;
3131
3135
break ;
3132
3136
}
@@ -3533,7 +3537,7 @@ MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser,
3533
3537
size_t offs_end = source.get_offs ();
3534
3538
sub_stack.peek ().insert (
3535
3539
{fragment->get_ident (),
3536
- { fragment->get_ident (), offs_begin, offs_end} });
3540
+ MatchedFragment ( fragment->get_ident (), offs_begin, offs_end) });
3537
3541
}
3538
3542
break ;
3539
3543
@@ -3607,6 +3611,7 @@ MacroExpander::match_n_matches (
3607
3611
match_amount = 0 ;
3608
3612
3609
3613
const MacroInvocLexer &source = parser.get_token_source ();
3614
+ std::vector<std::string> fragment_identifiers;
3610
3615
while (true )
3611
3616
{
3612
3617
// If the current token is a closing macro delimiter, break away.
@@ -3630,7 +3635,10 @@ MacroExpander::match_n_matches (
3630
3635
size_t offs_end = source.get_offs ();
3631
3636
sub_stack.peek ().insert (
3632
3637
{fragment->get_ident (),
3633
- {fragment->get_ident (), offs_begin, offs_end}});
3638
+ MatchedFragment (fragment->get_ident (), offs_begin,
3639
+ offs_end)});
3640
+
3641
+ fragment_identifiers.emplace_back (fragment->get_ident ());
3634
3642
}
3635
3643
break ;
3636
3644
@@ -3669,10 +3677,21 @@ MacroExpander::match_n_matches (
3669
3677
3670
3678
// Check if the amount of matches we got is valid: Is it more than the lower
3671
3679
// bound and less than the higher bound?
3672
- if (!hi_bound) // infinite amount, no upper bound
3673
- return match_amount >= lo_bound;
3674
- else
3675
- return match_amount >= lo_bound && match_amount <= hi_bound;
3680
+ auto result = hi_bound ? match_amount >= lo_bound && match_amount <= hi_bound
3681
+ : match_amount >= lo_bound;
3682
+
3683
+ // We can now set the amount to each fragment we matched in the substack
3684
+ auto &stack_map = sub_stack.peek ();
3685
+ for (auto &fragment_id : fragment_identifiers)
3686
+ {
3687
+ auto it = stack_map.find (fragment_id);
3688
+
3689
+ rust_assert (it != stack_map.end ());
3690
+
3691
+ it->second .set_match_amount (match_amount);
3692
+ }
3693
+
3694
+ return result;
3676
3695
}
3677
3696
3678
3697
bool
0 commit comments