@@ -177,7 +177,7 @@ impl<'tt> MatcherPos<'tt> {
177177 /// Generates the top-level matcher position in which the "dot" is before the first token of
178178 /// the matcher `ms`.
179179 fn new ( ms : & ' tt [ TokenTree ] ) -> Self {
180- let match_idx_hi = count_names ( ms) ;
180+ let match_idx_hi = count_metavar_decls ( ms) ;
181181 MatcherPos {
182182 // Start with the top level matcher given to us.
183183 top_elts : ms,
@@ -254,24 +254,24 @@ crate enum ParseResult<T> {
254254/// of metavars to the token trees they bind to.
255255crate type NamedParseResult = ParseResult < FxHashMap < MacroRulesNormalizedIdent , NamedMatch > > ;
256256
257- /// Count how many metavars are named in the given matcher `ms`.
258- pub ( super ) fn count_names ( ms : & [ TokenTree ] ) -> usize {
259- ms. iter ( ) . fold ( 0 , |count, elt| {
260- count
261- + match elt {
262- TokenTree :: Delimited ( _, delim) => count_names ( delim. inner_tts ( ) ) ,
257+ /// Count how many metavars declarations are in `matcher`.
258+ pub ( super ) fn count_metavar_decls ( matcher : & [ TokenTree ] ) -> usize {
259+ matcher
260+ . iter ( )
261+ . map ( |tt| {
262+ match tt {
263+ TokenTree :: Delimited ( _, delim) => count_metavar_decls ( delim. inner_tts ( ) ) ,
263264 TokenTree :: MetaVar ( ..) => 0 ,
264265 TokenTree :: MetaVarDecl ( ..) => 1 ,
265- // Panicking here would abort execution because `parse_tree` makes use of this
266- // function. In other words, RHS meta-variable expressions eventually end-up here.
267- //
268- // `0` is still returned to inform that no meta-variable was found. `Meta-variables
269- // != Meta-variable expressions`
266+ // RHS meta-variable expressions eventually end-up here. `0` is returned to inform
267+ // that no meta-variable was found, because "meta-variables" != "meta-variable
268+ // expressions".
270269 TokenTree :: MetaVarExpr ( ..) => 0 ,
271270 TokenTree :: Sequence ( _, seq) => seq. num_captures ,
272271 TokenTree :: Token ( ..) => 0 ,
273272 }
274- } )
273+ } )
274+ . sum ( )
275275}
276276
277277/// `NamedMatch` is a pattern-match result for a single metavar. All
0 commit comments