@@ -3,14 +3,14 @@ use crate::errors::{
33 CountRepetitionMisplaced , MetaVarExprUnrecognizedVar , MetaVarsDifSeqMatchers , MustRepeatOnce ,
44 NoSyntaxVarsExprRepeat , VarStillRepeating ,
55} ;
6- use crate :: mbe:: macro_parser:: { MatchedNonterminal , MatchedSeq , MatchedTokenTree , NamedMatch } ;
6+ use crate :: mbe:: macro_parser:: { NamedMatch , NamedMatch :: * } ;
77use crate :: mbe:: { self , KleeneOp , MetaVarExpr } ;
88use rustc_ast:: mut_visit:: { self , MutVisitor } ;
99use rustc_ast:: token:: { self , Delimiter , Token , TokenKind } ;
1010use rustc_ast:: tokenstream:: { DelimSpacing , DelimSpan , Spacing , TokenStream , TokenTree } ;
1111use 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 ;
1414use rustc_span:: hygiene:: { LocalExpnId , Transparency } ;
1515use rustc_span:: symbol:: { sym, Ident , MacroRulesNormalizedIdent } ;
1616use rustc_span:: { with_metavar_spans, Span , SyntaxContext } ;
@@ -250,26 +250,25 @@ pub(super) fn transcribe<'a>(
250250 // the meta-var.
251251 let ident = MacroRulesNormalizedIdent :: new ( original_ident) ;
252252 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 ) ) => {
255255 // `tt`s are emitted into the output stream directly as "raw tokens",
256256 // 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)
259258 }
260- MatchedNonterminal ( nt ) => {
259+ MatchedSingle ( ParseNtResult :: Nt ( nt ) ) => {
261260 // Other variables are emitted into the output stream as groups with
262261 // `Delimiter::Invisible` to maintain parsing priorities.
263262 // `Interpolated` is currently used for such groups in rustc parser.
264263 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)
267265 }
268266 MatchedSeq ( ..) => {
269267 // We were unable to descend far enough. This is an error.
270268 return Err ( cx. dcx ( ) . create_err ( VarStillRepeating { span : sp, ident } ) ) ;
271269 }
272- }
270+ } ;
271+ result. push ( tt)
273272 } else {
274273 // If we aren't able to match the meta-var, we push it back into the result but
275274 // with modified syntax context. (I believe this supports nested macros).
@@ -424,7 +423,7 @@ fn lookup_cur_matched<'a>(
424423 interpolations. get ( & ident) . map ( |mut matched| {
425424 for & ( idx, _) in repeats {
426425 match matched {
427- MatchedTokenTree ( _ ) | MatchedNonterminal ( _) => break ,
426+ MatchedSingle ( _) => break ,
428427 MatchedSeq ( ads) => matched = ads. get ( idx) . unwrap ( ) ,
429428 }
430429 }
@@ -514,7 +513,7 @@ fn lockstep_iter_size(
514513 let name = MacroRulesNormalizedIdent :: new ( * name) ;
515514 match lookup_cur_matched ( name, interpolations, repeats) {
516515 Some ( matched) => match matched {
517- MatchedTokenTree ( _ ) | MatchedNonterminal ( _) => LockstepIterSize :: Unconstrained ,
516+ MatchedSingle ( _) => LockstepIterSize :: Unconstrained ,
518517 MatchedSeq ( ads) => LockstepIterSize :: Constraint ( ads. len ( ) , name) ,
519518 } ,
520519 _ => LockstepIterSize :: Unconstrained ,
@@ -557,7 +556,7 @@ fn count_repetitions<'a>(
557556 // (or at the top-level of `matched` if no depth is given).
558557 fn count < ' a > ( depth_curr : usize , depth_max : usize , matched : & NamedMatch ) -> PResult < ' a , usize > {
559558 match matched {
560- MatchedTokenTree ( _ ) | MatchedNonterminal ( _) => Ok ( 1 ) ,
559+ MatchedSingle ( _) => Ok ( 1 ) ,
561560 MatchedSeq ( named_matches) => {
562561 if depth_curr == depth_max {
563562 Ok ( named_matches. len ( ) )
@@ -571,7 +570,7 @@ fn count_repetitions<'a>(
571570 /// Maximum depth
572571 fn depth ( counter : usize , matched : & NamedMatch ) -> usize {
573572 match matched {
574- MatchedTokenTree ( _ ) | MatchedNonterminal ( _) => counter,
573+ MatchedSingle ( _) => counter,
575574 MatchedSeq ( named_matches) => {
576575 let rslt = counter + 1 ;
577576 if let Some ( elem) = named_matches. first ( ) { depth ( rslt, elem) } else { rslt }
@@ -599,7 +598,7 @@ fn count_repetitions<'a>(
599598 }
600599 }
601600
602- if let MatchedTokenTree ( _ ) | MatchedNonterminal ( _) = matched {
601+ if let MatchedSingle ( _) = matched {
603602 return Err ( cx. dcx ( ) . create_err ( CountRepetitionMisplaced { span : sp. entire ( ) } ) ) ;
604603 }
605604
0 commit comments