@@ -76,7 +76,7 @@ crate use ParseResult::*;
76
76
use crate :: mbe:: { self , SequenceRepetition , TokenTree } ;
77
77
78
78
use rustc_ast:: token:: { self , DocComment , Nonterminal , Token } ;
79
- use rustc_parse:: parser:: Parser ;
79
+ use rustc_parse:: parser:: { NtOrTt , Parser } ;
80
80
use rustc_session:: parse:: ParseSess ;
81
81
use rustc_span:: symbol:: MacroRulesNormalizedIdent ;
82
82
@@ -275,7 +275,7 @@ pub(super) fn count_names(ms: &[TokenTree]) -> usize {
275
275
}
276
276
277
277
/// `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
279
279
/// (expr, item, etc).
280
280
///
281
281
/// The in-memory structure of a particular `NamedMatch` represents the match
@@ -306,32 +306,29 @@ pub(super) fn count_names(ms: &[TokenTree]) -> usize {
306
306
/// ```rust
307
307
/// MatchedSeq([
308
308
/// 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),
313
313
/// ]),
314
314
/// 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),
320
320
/// ])
321
321
/// ])
322
322
/// ```
323
323
#[ derive( Debug , Clone ) ]
324
324
crate enum NamedMatch {
325
325
MatchedSeq ( Lrc < NamedMatchVec > ) ,
326
326
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 ) ,
330
329
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 > ) ,
335
332
}
336
333
337
334
/// Takes a slice of token trees `ms` representing a matcher which successfully matched input
@@ -519,13 +516,14 @@ impl<'tt> TtParser<'tt> {
519
516
}
520
517
521
518
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) {
529
527
item. idx += 1 ;
530
528
self . next_items . push ( item) ;
531
529
}
@@ -677,8 +675,8 @@ impl<'tt> TtParser<'tt> {
677
675
Ok ( nt) => nt,
678
676
} ;
679
677
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 ) ,
682
680
} ;
683
681
item. push_match ( match_cur, m) ;
684
682
item. idx += 1 ;
0 commit comments