@@ -177,7 +177,7 @@ impl<'tt> MatcherPos<'tt> {
177
177
/// Generates the top-level matcher position in which the "dot" is before the first token of
178
178
/// the matcher `ms`.
179
179
fn new ( ms : & ' tt [ TokenTree ] ) -> Self {
180
- let match_idx_hi = count_names ( ms) ;
180
+ let match_idx_hi = count_metavar_decls ( ms) ;
181
181
MatcherPos {
182
182
// Start with the top level matcher given to us.
183
183
top_elts : ms,
@@ -254,24 +254,24 @@ crate enum ParseResult<T> {
254
254
/// of metavars to the token trees they bind to.
255
255
crate type NamedParseResult = ParseResult < FxHashMap < MacroRulesNormalizedIdent , NamedMatch > > ;
256
256
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 ( ) ) ,
263
264
TokenTree :: MetaVar ( ..) => 0 ,
264
265
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".
270
269
TokenTree :: MetaVarExpr ( ..) => 0 ,
271
270
TokenTree :: Sequence ( _, seq) => seq. num_captures ,
272
271
TokenTree :: Token ( ..) => 0 ,
273
272
}
274
- } )
273
+ } )
274
+ . sum ( )
275
275
}
276
276
277
277
/// `NamedMatch` is a pattern-match result for a single metavar. All
0 commit comments