@@ -3,14 +3,14 @@ use crate::errors::{
3
3
CountRepetitionMisplaced , MetaVarExprUnrecognizedVar , MetaVarsDifSeqMatchers , MustRepeatOnce ,
4
4
NoSyntaxVarsExprRepeat , VarStillRepeating ,
5
5
} ;
6
- use crate :: mbe:: macro_parser:: { MatchedNonterminal , MatchedSeq , MatchedTokenTree , NamedMatch } ;
6
+ use crate :: mbe:: macro_parser:: { NamedMatch , NamedMatch :: * } ;
7
7
use crate :: mbe:: { self , KleeneOp , MetaVarExpr } ;
8
8
use rustc_ast:: mut_visit:: { self , MutVisitor } ;
9
9
use rustc_ast:: token:: { self , Delimiter , Token , TokenKind } ;
10
10
use rustc_ast:: tokenstream:: { DelimSpacing , DelimSpan , Spacing , TokenStream , TokenTree } ;
11
11
use rustc_data_structures:: fx:: FxHashMap ;
12
- use rustc_errors:: Diag ;
13
- use rustc_errors :: { pluralize , PResult } ;
12
+ use rustc_errors:: { pluralize , Diag , PResult } ;
13
+ use rustc_parse :: parser :: ParseNtResult ;
14
14
use rustc_span:: hygiene:: { LocalExpnId , Transparency } ;
15
15
use rustc_span:: symbol:: { sym, Ident , MacroRulesNormalizedIdent } ;
16
16
use rustc_span:: { with_metavar_spans, Span , SyntaxContext } ;
@@ -250,26 +250,25 @@ pub(super) fn transcribe<'a>(
250
250
// the meta-var.
251
251
let ident = MacroRulesNormalizedIdent :: new ( original_ident) ;
252
252
if let Some ( cur_matched) = lookup_cur_matched ( ident, interp, & repeats) {
253
- match cur_matched {
254
- MatchedTokenTree ( tt ) => {
253
+ let tt = match cur_matched {
254
+ MatchedSingle ( ParseNtResult :: Tt ( tt ) ) => {
255
255
// `tt`s are emitted into the output stream directly as "raw tokens",
256
256
// without wrapping them into groups.
257
- let tt = maybe_use_metavar_location ( cx, & stack, sp, tt, & mut marker) ;
258
- result. push ( tt) ;
257
+ maybe_use_metavar_location ( cx, & stack, sp, tt, & mut marker)
259
258
}
260
- MatchedNonterminal ( nt ) => {
259
+ MatchedSingle ( ParseNtResult :: Nt ( nt ) ) => {
261
260
// Other variables are emitted into the output stream as groups with
262
261
// `Delimiter::Invisible` to maintain parsing priorities.
263
262
// `Interpolated` is currently used for such groups in rustc parser.
264
263
marker. visit_span ( & mut sp) ;
265
- result
266
- . push ( TokenTree :: token_alone ( token:: Interpolated ( nt. clone ( ) ) , sp) ) ;
264
+ TokenTree :: token_alone ( token:: Interpolated ( nt. clone ( ) ) , sp)
267
265
}
268
266
MatchedSeq ( ..) => {
269
267
// We were unable to descend far enough. This is an error.
270
268
return Err ( cx. dcx ( ) . create_err ( VarStillRepeating { span : sp, ident } ) ) ;
271
269
}
272
- }
270
+ } ;
271
+ result. push ( tt)
273
272
} else {
274
273
// If we aren't able to match the meta-var, we push it back into the result but
275
274
// with modified syntax context. (I believe this supports nested macros).
@@ -424,7 +423,7 @@ fn lookup_cur_matched<'a>(
424
423
interpolations. get ( & ident) . map ( |mut matched| {
425
424
for & ( idx, _) in repeats {
426
425
match matched {
427
- MatchedTokenTree ( _ ) | MatchedNonterminal ( _) => break ,
426
+ MatchedSingle ( _) => break ,
428
427
MatchedSeq ( ads) => matched = ads. get ( idx) . unwrap ( ) ,
429
428
}
430
429
}
@@ -514,7 +513,7 @@ fn lockstep_iter_size(
514
513
let name = MacroRulesNormalizedIdent :: new ( * name) ;
515
514
match lookup_cur_matched ( name, interpolations, repeats) {
516
515
Some ( matched) => match matched {
517
- MatchedTokenTree ( _ ) | MatchedNonterminal ( _) => LockstepIterSize :: Unconstrained ,
516
+ MatchedSingle ( _) => LockstepIterSize :: Unconstrained ,
518
517
MatchedSeq ( ads) => LockstepIterSize :: Constraint ( ads. len ( ) , name) ,
519
518
} ,
520
519
_ => LockstepIterSize :: Unconstrained ,
@@ -557,7 +556,7 @@ fn count_repetitions<'a>(
557
556
// (or at the top-level of `matched` if no depth is given).
558
557
fn count < ' a > ( depth_curr : usize , depth_max : usize , matched : & NamedMatch ) -> PResult < ' a , usize > {
559
558
match matched {
560
- MatchedTokenTree ( _ ) | MatchedNonterminal ( _) => Ok ( 1 ) ,
559
+ MatchedSingle ( _) => Ok ( 1 ) ,
561
560
MatchedSeq ( named_matches) => {
562
561
if depth_curr == depth_max {
563
562
Ok ( named_matches. len ( ) )
@@ -571,7 +570,7 @@ fn count_repetitions<'a>(
571
570
/// Maximum depth
572
571
fn depth ( counter : usize , matched : & NamedMatch ) -> usize {
573
572
match matched {
574
- MatchedTokenTree ( _ ) | MatchedNonterminal ( _) => counter,
573
+ MatchedSingle ( _) => counter,
575
574
MatchedSeq ( named_matches) => {
576
575
let rslt = counter + 1 ;
577
576
if let Some ( elem) = named_matches. first ( ) { depth ( rslt, elem) } else { rslt }
@@ -599,7 +598,7 @@ fn count_repetitions<'a>(
599
598
}
600
599
}
601
600
602
- if let MatchedTokenTree ( _ ) | MatchedNonterminal ( _) = matched {
601
+ if let MatchedSingle ( _) = matched {
603
602
return Err ( cx. dcx ( ) . create_err ( CountRepetitionMisplaced { span : sp. entire ( ) } ) ) ;
604
603
}
605
604
0 commit comments