@@ -131,7 +131,7 @@ pub(super) enum MatcherLoc {
131
131
MetaVarDecl {
132
132
span : Span ,
133
133
bind : Ident ,
134
- kind : Option < NonterminalKind > ,
134
+ kind : NonterminalKind ,
135
135
next_metavar : usize ,
136
136
seq_depth : usize ,
137
137
} ,
@@ -189,7 +189,7 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
189
189
locs. push ( MatcherLoc :: MetaVarDecl {
190
190
span,
191
191
bind,
192
- kind,
192
+ kind : kind . unwrap ( ) , // presence was checked for earlier
193
193
next_metavar : * next_metavar,
194
194
seq_depth,
195
195
} ) ;
@@ -409,7 +409,6 @@ impl TtParser {
409
409
/// track of through the mps generated.
410
410
fn parse_tt_inner (
411
411
& mut self ,
412
- sess : & ParseSess ,
413
412
matcher : & [ MatcherLoc ] ,
414
413
token : & Token ,
415
414
) -> Option < NamedParseResult > {
@@ -508,20 +507,12 @@ impl TtParser {
508
507
mp. idx = idx_first;
509
508
self . cur_mps . push ( mp) ;
510
509
}
511
- & MatcherLoc :: MetaVarDecl { span , kind, .. } => {
510
+ & MatcherLoc :: MetaVarDecl { kind, .. } => {
512
511
// Built-in nonterminals never start with these tokens, so we can eliminate
513
512
// them from consideration. We use the span of the metavariable declaration
514
513
// to determine any edition-specific matching behavior for non-terminals.
515
- if let Some ( kind) = kind {
516
- if Parser :: nonterminal_may_begin_with ( kind, token) {
517
- self . bb_mps . push ( mp) ;
518
- }
519
- } else {
520
- // Both this check and the one in `nameize` are necessary, surprisingly.
521
- if sess. missing_fragment_specifiers . borrow_mut ( ) . remove ( & span) . is_some ( ) {
522
- // E.g. `$e` instead of `$e:expr`.
523
- return Some ( Error ( span, "missing fragment specifier" . to_string ( ) ) ) ;
524
- }
514
+ if Parser :: nonterminal_may_begin_with ( kind, token) {
515
+ self . bb_mps . push ( mp) ;
525
516
}
526
517
}
527
518
MatcherLoc :: Eof => {
@@ -547,7 +538,7 @@ impl TtParser {
547
538
// Need to take ownership of the matches from within the `Lrc`.
548
539
Lrc :: make_mut ( & mut eof_mp. matches ) ;
549
540
let matches = Lrc :: try_unwrap ( eof_mp. matches ) . unwrap ( ) . into_iter ( ) ;
550
- self . nameize ( sess , matcher, matches)
541
+ self . nameize ( matcher, matches)
551
542
}
552
543
EofMatcherPositions :: Multiple => {
553
544
Error ( token. span , "ambiguity: multiple successful parses" . to_string ( ) )
@@ -585,7 +576,7 @@ impl TtParser {
585
576
586
577
// Process `cur_mps` until either we have finished the input or we need to get some
587
578
// parsing from the black-box parser done.
588
- if let Some ( res) = self . parse_tt_inner ( & parser . sess , matcher, & parser. token ) {
579
+ if let Some ( res) = self . parse_tt_inner ( matcher, & parser. token ) {
589
580
return res;
590
581
}
591
582
@@ -615,11 +606,7 @@ impl TtParser {
615
606
let mut mp = self . bb_mps . pop ( ) . unwrap ( ) ;
616
607
let loc = & matcher[ mp. idx ] ;
617
608
if let & MatcherLoc :: MetaVarDecl {
618
- span,
619
- kind : Some ( kind) ,
620
- next_metavar,
621
- seq_depth,
622
- ..
609
+ span, kind, next_metavar, seq_depth, ..
623
610
} = loc
624
611
{
625
612
// We use the span of the metavariable declaration to determine any
@@ -668,7 +655,7 @@ impl TtParser {
668
655
. bb_mps
669
656
. iter ( )
670
657
. map ( |mp| match & matcher[ mp. idx ] {
671
- MatcherLoc :: MetaVarDecl { bind, kind : Some ( kind ) , .. } => {
658
+ MatcherLoc :: MetaVarDecl { bind, kind, .. } => {
672
659
format ! ( "{} ('{}')" , kind, bind)
673
660
}
674
661
_ => unreachable ! ( ) ,
@@ -692,29 +679,20 @@ impl TtParser {
692
679
693
680
fn nameize < I : Iterator < Item = NamedMatch > > (
694
681
& self ,
695
- sess : & ParseSess ,
696
682
matcher : & [ MatcherLoc ] ,
697
683
mut res : I ,
698
684
) -> NamedParseResult {
699
685
// Make that each metavar has _exactly one_ binding. If so, insert the binding into the
700
686
// `NamedParseResult`. Otherwise, it's an error.
701
687
let mut ret_val = FxHashMap :: default ( ) ;
702
688
for loc in matcher {
703
- if let & MatcherLoc :: MetaVarDecl { span, bind, kind, .. } = loc {
704
- if kind. is_some ( ) {
705
- match ret_val. entry ( MacroRulesNormalizedIdent :: new ( bind) ) {
706
- Vacant ( spot) => spot. insert ( res. next ( ) . unwrap ( ) ) ,
707
- Occupied ( ..) => {
708
- return Error ( span, format ! ( "duplicated bind name: {}" , bind) ) ;
709
- }
710
- } ;
711
- } else {
712
- // Both this check and the one in `parse_tt_inner` are necessary, surprisingly.
713
- if sess. missing_fragment_specifiers . borrow_mut ( ) . remove ( & span) . is_some ( ) {
714
- // E.g. `$e` instead of `$e:expr`.
715
- return Error ( span, "missing fragment specifier" . to_string ( ) ) ;
689
+ if let & MatcherLoc :: MetaVarDecl { span, bind, .. } = loc {
690
+ match ret_val. entry ( MacroRulesNormalizedIdent :: new ( bind) ) {
691
+ Vacant ( spot) => spot. insert ( res. next ( ) . unwrap ( ) ) ,
692
+ Occupied ( ..) => {
693
+ return Error ( span, format ! ( "duplicated bind name: {}" , bind) ) ;
716
694
}
717
- }
695
+ } ;
718
696
}
719
697
}
720
698
Success ( ret_val)
0 commit comments