@@ -443,6 +443,29 @@ impl<'tt> TtParser<'tt> {
443
443
444
444
while let Some ( mut mp) = self . cur_mps . pop ( ) {
445
445
match & self . locs [ mp. idx ] {
446
+ MatcherLoc :: Token { token : t } => {
447
+ // If it's a doc comment, we just ignore it and move on to the next tt in the
448
+ // matcher. This is a bug, but #95267 showed that existing programs rely on
449
+ // this behaviour, and changing it would require some care and a transition
450
+ // period.
451
+ //
452
+ // If the token matches, we can just advance the parser.
453
+ //
454
+ // Otherwise, this match has failed, there is nothing to do, and hopefully
455
+ // another mp in `cur_mps` will match.
456
+ if matches ! ( t, Token { kind: DocComment ( ..) , .. } ) {
457
+ mp. idx += 1 ;
458
+ self . cur_mps . push ( mp) ;
459
+ } else if token_name_eq ( & t, token) {
460
+ mp. idx += 1 ;
461
+ self . next_mps . push ( mp) ;
462
+ }
463
+ }
464
+ MatcherLoc :: Delimited => {
465
+ // Entering the delimeter is trivial.
466
+ mp. idx += 1 ;
467
+ self . cur_mps . push ( mp) ;
468
+ }
446
469
& MatcherLoc :: Sequence {
447
470
op,
448
471
num_metavar_decls,
@@ -471,37 +494,6 @@ impl<'tt> TtParser<'tt> {
471
494
mp. idx += 1 ;
472
495
self . cur_mps . push ( mp) ;
473
496
}
474
- MatcherLoc :: MetaVarDecl { kind, .. } => {
475
- // Built-in nonterminals never start with these tokens, so we can eliminate
476
- // them from consideration. We use the span of the metavariable declaration
477
- // to determine any edition-specific matching behavior for non-terminals.
478
- if Parser :: nonterminal_may_begin_with ( * kind, token) {
479
- self . bb_mps . push ( mp) ;
480
- }
481
- }
482
- MatcherLoc :: Delimited => {
483
- // Entering the delimeter is trivial.
484
- mp. idx += 1 ;
485
- self . cur_mps . push ( mp) ;
486
- }
487
- MatcherLoc :: Token { token : t } => {
488
- // If it's a doc comment, we just ignore it and move on to the next tt in the
489
- // matcher. This is a bug, but #95267 showed that existing programs rely on
490
- // this behaviour, and changing it would require some care and a transition
491
- // period.
492
- //
493
- // If the token matches, we can just advance the parser.
494
- //
495
- // Otherwise, this match has failed, there is nothing to do, and hopefully
496
- // another mp in `cur_mps` will match.
497
- if matches ! ( t, Token { kind: DocComment ( ..) , .. } ) {
498
- mp. idx += 1 ;
499
- self . cur_mps . push ( mp) ;
500
- } else if token_name_eq ( & t, token) {
501
- mp. idx += 1 ;
502
- self . next_mps . push ( mp) ;
503
- }
504
- }
505
497
& MatcherLoc :: SequenceKleeneOpNoSep { op, idx_first } => {
506
498
// We are past the end of a sequence with no separator. Try ending the
507
499
// sequence. If that's not possible, `ending_mp` will fail quietly when it is
@@ -540,6 +532,14 @@ impl<'tt> TtParser<'tt> {
540
532
mp. idx = idx_first;
541
533
self . cur_mps . push ( mp) ;
542
534
}
535
+ MatcherLoc :: MetaVarDecl { kind, .. } => {
536
+ // Built-in nonterminals never start with these tokens, so we can eliminate
537
+ // them from consideration. We use the span of the metavariable declaration
538
+ // to determine any edition-specific matching behavior for non-terminals.
539
+ if Parser :: nonterminal_may_begin_with ( * kind, token) {
540
+ self . bb_mps . push ( mp) ;
541
+ }
542
+ }
543
543
MatcherLoc :: Eof => {
544
544
// We are past the matcher's end, and not in a sequence. Try to end things.
545
545
debug_assert_eq ! ( mp. idx, self . locs. len( ) - 1 ) ;
0 commit comments