@@ -392,7 +392,7 @@ pub fn compile_declarative_macro(
392
392
393
393
let lhs_nm = Ident :: new ( sym:: lhs, span) ;
394
394
let rhs_nm = Ident :: new ( sym:: rhs, span) ;
395
- let tt_spec = Some ( NonterminalKind :: TT ) ;
395
+ let tt_spec = NonterminalKind :: TT ;
396
396
let macro_rules = macro_def. macro_rules ;
397
397
398
398
// Parse the macro_rules! invocation
@@ -407,9 +407,9 @@ pub fn compile_declarative_macro(
407
407
DelimSpan :: dummy( ) ,
408
408
mbe:: SequenceRepetition {
409
409
tts: vec![
410
- mbe:: TokenTree :: MetaVarDecl ( span, lhs_nm, tt_spec) ,
410
+ mbe:: TokenTree :: MetaVarDecl { span, name : lhs_nm, kind : tt_spec } ,
411
411
mbe:: TokenTree :: token( token:: FatArrow , span) ,
412
- mbe:: TokenTree :: MetaVarDecl ( span, rhs_nm, tt_spec) ,
412
+ mbe:: TokenTree :: MetaVarDecl { span, name : rhs_nm, kind : tt_spec } ,
413
413
] ,
414
414
separator: Some ( Token :: new(
415
415
if macro_rules { token:: Semi } else { token:: Comma } ,
@@ -448,6 +448,7 @@ pub fn compile_declarative_macro(
448
448
match tt_parser. parse_tt ( & mut Cow :: Owned ( parser) , & argument_gram, & mut NoopTracker ) {
449
449
Success ( m) => m,
450
450
Failure ( ( ) ) => {
451
+ debug ! ( "failed to parse macro tt" ) ;
451
452
// The fast `NoopTracker` doesn't have any info on failure, so we need to retry it
452
453
// with another one that gives us the information we need.
453
454
// For this we need to reclone the macro body as the previous parser consumed it.
@@ -616,7 +617,7 @@ fn is_empty_token_tree(sess: &Session, seq: &mbe::SequenceRepetition) -> bool {
616
617
let mut iter = seq. tts . iter ( ) . peekable ( ) ;
617
618
while let Some ( tt) = iter. next ( ) {
618
619
match tt {
619
- mbe:: TokenTree :: MetaVarDecl ( _ , _ , Some ( NonterminalKind :: Vis ) ) => { }
620
+ mbe:: TokenTree :: MetaVarDecl { kind : NonterminalKind :: Vis , .. } => { }
620
621
mbe:: TokenTree :: Token ( t @ Token { kind : DocComment ( ..) , .. } ) => {
621
622
let mut now = t;
622
623
while let Some ( & mbe:: TokenTree :: Token (
@@ -651,7 +652,7 @@ fn check_redundant_vis_repetition(
651
652
) {
652
653
let is_zero_or_one: bool = seq. kleene . op == KleeneOp :: ZeroOrOne ;
653
654
let is_vis = seq. tts . first ( ) . map_or ( false , |tt| {
654
- matches ! ( tt, mbe:: TokenTree :: MetaVarDecl ( _ , _ , Some ( NonterminalKind :: Vis ) ) )
655
+ matches ! ( tt, mbe:: TokenTree :: MetaVarDecl { kind : NonterminalKind :: Vis , .. } )
655
656
} ) ;
656
657
657
658
if is_vis && is_zero_or_one {
@@ -678,7 +679,7 @@ fn check_lhs_no_empty_seq(sess: &Session, tts: &[mbe::TokenTree]) -> Result<(),
678
679
match tt {
679
680
TokenTree :: Token ( ..)
680
681
| TokenTree :: MetaVar ( ..)
681
- | TokenTree :: MetaVarDecl ( .. )
682
+ | TokenTree :: MetaVarDecl { .. }
682
683
| TokenTree :: MetaVarExpr ( ..) => ( ) ,
683
684
TokenTree :: Delimited ( .., del) => check_lhs_no_empty_seq ( sess, & del. tts ) ?,
684
685
TokenTree :: Sequence ( span, seq) => {
@@ -777,7 +778,7 @@ impl<'tt> FirstSets<'tt> {
777
778
match tt {
778
779
TokenTree :: Token ( ..)
779
780
| TokenTree :: MetaVar ( ..)
780
- | TokenTree :: MetaVarDecl ( .. )
781
+ | TokenTree :: MetaVarDecl { .. }
781
782
| TokenTree :: MetaVarExpr ( ..) => {
782
783
first. replace_with ( TtHandle :: TtRef ( tt) ) ;
783
784
}
@@ -845,7 +846,7 @@ impl<'tt> FirstSets<'tt> {
845
846
match tt {
846
847
TokenTree :: Token ( ..)
847
848
| TokenTree :: MetaVar ( ..)
848
- | TokenTree :: MetaVarDecl ( .. )
849
+ | TokenTree :: MetaVarDecl { .. }
849
850
| TokenTree :: MetaVarExpr ( ..) => {
850
851
first. add_one ( TtHandle :: TtRef ( tt) ) ;
851
852
return first;
@@ -1084,7 +1085,7 @@ fn check_matcher_core<'tt>(
1084
1085
match token {
1085
1086
TokenTree :: Token ( ..)
1086
1087
| TokenTree :: MetaVar ( ..)
1087
- | TokenTree :: MetaVarDecl ( .. )
1088
+ | TokenTree :: MetaVarDecl { .. }
1088
1089
| TokenTree :: MetaVarExpr ( ..) => {
1089
1090
if token_can_be_followed_by_any ( token) {
1090
1091
// don't need to track tokens that work with any,
@@ -1152,7 +1153,7 @@ fn check_matcher_core<'tt>(
1152
1153
// Now `last` holds the complete set of NT tokens that could
1153
1154
// end the sequence before SUFFIX. Check that every one works with `suffix`.
1154
1155
for tt in & last. tokens {
1155
- if let & TokenTree :: MetaVarDecl ( span, name, Some ( kind) ) = tt. get ( ) {
1156
+ if let & TokenTree :: MetaVarDecl { span, name, kind } = tt. get ( ) {
1156
1157
for next_token in & suffix_first. tokens {
1157
1158
let next_token = next_token. get ( ) ;
1158
1159
@@ -1172,11 +1173,11 @@ fn check_matcher_core<'tt>(
1172
1173
)
1173
1174
{
1174
1175
// It is suggestion to use pat_param, for example: $x:pat -> $x:pat_param.
1175
- let suggestion = quoted_tt_to_string ( & TokenTree :: MetaVarDecl (
1176
+ let suggestion = quoted_tt_to_string ( & TokenTree :: MetaVarDecl {
1176
1177
span,
1177
1178
name,
1178
- Some ( NonterminalKind :: Pat ( PatParam { inferred : false } ) ) ,
1179
- ) ) ;
1179
+ kind : NonterminalKind :: Pat ( PatParam { inferred : false } ) ,
1180
+ } ) ;
1180
1181
sess. psess . buffer_lint (
1181
1182
RUST_2021_INCOMPATIBLE_OR_PATTERNS ,
1182
1183
span,
@@ -1212,11 +1213,11 @@ fn check_matcher_core<'tt>(
1212
1213
&& sess. psess . edition . at_least_rust_2021 ( )
1213
1214
&& next_token. is_token ( & token:: Or )
1214
1215
{
1215
- let suggestion = quoted_tt_to_string ( & TokenTree :: MetaVarDecl (
1216
+ let suggestion = quoted_tt_to_string ( & TokenTree :: MetaVarDecl {
1216
1217
span,
1217
1218
name,
1218
- Some ( NonterminalKind :: Pat ( PatParam { inferred : false } ) ) ,
1219
- ) ) ;
1219
+ kind : NonterminalKind :: Pat ( PatParam { inferred : false } ) ,
1220
+ } ) ;
1220
1221
err. span_suggestion (
1221
1222
span,
1222
1223
"try a `pat_param` fragment specifier instead" ,
@@ -1254,7 +1255,7 @@ fn check_matcher_core<'tt>(
1254
1255
}
1255
1256
1256
1257
fn token_can_be_followed_by_any ( tok : & mbe:: TokenTree ) -> bool {
1257
- if let mbe:: TokenTree :: MetaVarDecl ( _ , _ , Some ( kind) ) = * tok {
1258
+ if let mbe:: TokenTree :: MetaVarDecl { kind, .. } = * tok {
1258
1259
frag_can_be_followed_by_any ( kind)
1259
1260
} else {
1260
1261
// (Non NT's can always be followed by anything in matchers.)
@@ -1367,7 +1368,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
1367
1368
}
1368
1369
_ => IsInFollow :: No ( TOKENS ) ,
1369
1370
} ,
1370
- TokenTree :: MetaVarDecl ( _ , _ , Some ( NonterminalKind :: Block ) ) => IsInFollow :: Yes ,
1371
+ TokenTree :: MetaVarDecl { kind : NonterminalKind :: Block , .. } => IsInFollow :: Yes ,
1371
1372
_ => IsInFollow :: No ( TOKENS ) ,
1372
1373
}
1373
1374
}
@@ -1400,11 +1401,10 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
1400
1401
}
1401
1402
}
1402
1403
} ,
1403
- TokenTree :: MetaVarDecl (
1404
- _,
1405
- _,
1406
- Some ( NonterminalKind :: Ident | NonterminalKind :: Ty | NonterminalKind :: Path ) ,
1407
- ) => IsInFollow :: Yes ,
1404
+ TokenTree :: MetaVarDecl {
1405
+ kind : NonterminalKind :: Ident | NonterminalKind :: Ty | NonterminalKind :: Path ,
1406
+ ..
1407
+ } => IsInFollow :: Yes ,
1408
1408
_ => IsInFollow :: No ( TOKENS ) ,
1409
1409
}
1410
1410
}
@@ -1416,8 +1416,7 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
1416
1416
match tt {
1417
1417
mbe:: TokenTree :: Token ( token) => pprust:: token_to_string ( token) . into ( ) ,
1418
1418
mbe:: TokenTree :: MetaVar ( _, name) => format ! ( "${name}" ) ,
1419
- mbe:: TokenTree :: MetaVarDecl ( _, name, Some ( kind) ) => format ! ( "${name}:{kind}" ) ,
1420
- mbe:: TokenTree :: MetaVarDecl ( _, name, None ) => format ! ( "${name}:" ) ,
1419
+ mbe:: TokenTree :: MetaVarDecl { name, kind, .. } => format ! ( "${name}:{kind}" ) ,
1421
1420
_ => panic ! (
1422
1421
"{}" ,
1423
1422
"unexpected mbe::TokenTree::{Sequence or Delimited} \
0 commit comments