@@ -76,7 +76,7 @@ crate use ParseResult::*;
7676use crate :: mbe:: { self , SequenceRepetition , TokenTree } ;
7777
7878use rustc_ast:: token:: { self , DocComment , Nonterminal , Token } ;
79- use rustc_parse:: parser:: Parser ;
79+ use rustc_parse:: parser:: { NtOrTt , Parser } ;
8080use rustc_session:: parse:: ParseSess ;
8181use rustc_span:: symbol:: MacroRulesNormalizedIdent ;
8282
@@ -275,7 +275,7 @@ pub(super) fn count_names(ms: &[TokenTree]) -> usize {
275275}
276276
277277/// `NamedMatch` is a pattern-match result for a single metavar. All
278- /// `MatchedNtNonTt `s in the `NamedMatch` have the same non-terminal type
278+ /// `MatchedNonterminal `s in the `NamedMatch` have the same non-terminal type
279279/// (expr, item, etc).
280280///
281281/// The in-memory structure of a particular `NamedMatch` represents the match
@@ -306,32 +306,29 @@ pub(super) fn count_names(ms: &[TokenTree]) -> usize {
306306/// ```rust
307307/// MatchedSeq([
308308/// MatchedSeq([
309- /// MatchedNtNonTt (a),
310- /// MatchedNtNonTt (b),
311- /// MatchedNtNonTt (c),
312- /// MatchedNtNonTt (d),
309+ /// MatchedNonterminal (a),
310+ /// MatchedNonterminal (b),
311+ /// MatchedNonterminal (c),
312+ /// MatchedNonterminal (d),
313313/// ]),
314314/// MatchedSeq([
315- /// MatchedNtNonTt (a),
316- /// MatchedNtNonTt (b),
317- /// MatchedNtNonTt (c),
318- /// MatchedNtNonTt (d),
319- /// MatchedNtNonTt (e),
315+ /// MatchedNonterminal (a),
316+ /// MatchedNonterminal (b),
317+ /// MatchedNonterminal (c),
318+ /// MatchedNonterminal (d),
319+ /// MatchedNonterminal (e),
320320/// ])
321321/// ])
322322/// ```
323323#[ derive( Debug , Clone ) ]
324324crate enum NamedMatch {
325325 MatchedSeq ( Lrc < NamedMatchVec > ) ,
326326
327- // This variant should never hold an `NtTT`. `MatchedNtTt` should be used
328- // for that case.
329- MatchedNtNonTt ( Lrc < Nonterminal > ) ,
327+ // A metavar match of type `tt`.
328+ MatchedTokenTree ( rustc_ast:: tokenstream:: TokenTree ) ,
330329
331- // `NtTT` is handled without any cloning when transcribing, unlike other
332- // nonterminals. Therefore, an `Lrc` isn't helpful and causes unnecessary
333- // allocations. Hence this separate variant.
334- MatchedNtTt ( rustc_ast:: tokenstream:: TokenTree ) ,
330+ // A metavar match of any type other than `tt`.
331+ MatchedNonterminal ( Lrc < Nonterminal > ) ,
335332}
336333
337334/// Takes a slice of token trees `ms` representing a matcher which successfully matched input
@@ -519,13 +516,14 @@ impl<'tt> TtParser<'tt> {
519516 }
520517
521518 TokenTree :: Token ( t) => {
522- // Doc comments cannot appear in a matcher.
523- debug_assert ! ( !matches!( t, Token { kind: DocComment ( ..) , .. } ) ) ;
524-
525- // If the token matches, we can just advance the parser. Otherwise, this
526- // match hash failed, there is nothing to do, and hopefully another item in
527- // `cur_items` will match.
528- if token_name_eq ( & t, token) {
519+ // If it's a doc comment, we just ignore it and move on to the next tt in
520+ // the matcher. If the token matches, we can just advance the parser.
521+ // Otherwise, this match has failed, there is nothing to do, and hopefully
522+ // another item in `cur_items` will match.
523+ if matches ! ( t, Token { kind: DocComment ( ..) , .. } ) {
524+ item. idx += 1 ;
525+ self . cur_items . push ( item) ;
526+ } else if token_name_eq ( & t, token) {
529527 item. idx += 1 ;
530528 self . next_items . push ( item) ;
531529 }
@@ -677,8 +675,8 @@ impl<'tt> TtParser<'tt> {
677675 Ok ( nt) => nt,
678676 } ;
679677 let m = match nt {
680- Nonterminal :: NtTT ( tt ) => MatchedNtTt ( tt ) ,
681- _ => MatchedNtNonTt ( Lrc :: new ( nt ) ) ,
678+ NtOrTt :: Nt ( nt ) => MatchedNonterminal ( Lrc :: new ( nt ) ) ,
679+ NtOrTt :: Tt ( tt ) => MatchedTokenTree ( tt ) ,
682680 } ;
683681 item. push_match ( match_cur, m) ;
684682 item. idx += 1 ;
0 commit comments