@@ -11,7 +11,7 @@ use crate::mbe::transcribe::transcribe;
11
11
use ast:: token:: IdentIsRaw ;
12
12
use rustc_ast as ast;
13
13
use rustc_ast:: token:: { self , Delimiter , NonterminalKind , Token , TokenKind , TokenKind :: * } ;
14
- use rustc_ast:: tokenstream:: { DelimSpan , TokenStream } ;
14
+ use rustc_ast:: tokenstream:: { DelimSpan , Spacing , TokenStream } ;
15
15
use rustc_ast:: { NodeId , DUMMY_NODE_ID } ;
16
16
use rustc_ast_pretty:: pprust;
17
17
use rustc_attr:: { self as attr, TransparencyError } ;
@@ -402,7 +402,7 @@ pub fn compile_declarative_macro(
402
402
mbe:: SequenceRepetition {
403
403
tts: vec![
404
404
mbe:: TokenTree :: MetaVarDecl ( def. span, lhs_nm, tt_spec) ,
405
- mbe:: TokenTree :: token ( token:: FatArrow , def. span) ,
405
+ mbe:: TokenTree :: token_alone ( token:: FatArrow , def. span) ,
406
406
mbe:: TokenTree :: MetaVarDecl ( def. span, rhs_nm, tt_spec) ,
407
407
] ,
408
408
separator: Some ( Token :: new(
@@ -417,7 +417,7 @@ pub fn compile_declarative_macro(
417
417
mbe:: TokenTree :: Sequence (
418
418
DelimSpan :: dummy( ) ,
419
419
mbe:: SequenceRepetition {
420
- tts: vec![ mbe:: TokenTree :: token (
420
+ tts: vec![ mbe:: TokenTree :: token_alone (
421
421
if macro_rules { token:: Semi } else { token:: Comma } ,
422
422
def. span,
423
423
) ] ,
@@ -627,10 +627,11 @@ fn is_empty_token_tree(sess: &Session, seq: &mbe::SequenceRepetition) -> bool {
627
627
while let Some ( tt) = iter. next ( ) {
628
628
match tt {
629
629
mbe:: TokenTree :: MetaVarDecl ( _, _, Some ( NonterminalKind :: Vis ) ) => { }
630
- mbe:: TokenTree :: Token ( t @ Token { kind : DocComment ( ..) , .. } ) => {
630
+ mbe:: TokenTree :: Token ( t @ Token { kind : DocComment ( ..) , .. } , _ ) => {
631
631
let mut now = t;
632
632
while let Some ( & mbe:: TokenTree :: Token (
633
633
next @ Token { kind : DocComment ( ..) , .. } ,
634
+ _,
634
635
) ) = iter. peek ( )
635
636
{
636
637
now = next;
@@ -696,10 +697,10 @@ fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool {
696
697
match rhs {
697
698
mbe:: TokenTree :: Delimited ( .., d) => {
698
699
let has_compile_error = d. tts . array_windows :: < 3 > ( ) . any ( |[ ident, bang, args] | {
699
- if let mbe:: TokenTree :: Token ( ident) = ident
700
+ if let mbe:: TokenTree :: Token ( ident, _ ) = ident
700
701
&& let TokenKind :: Ident ( ident, _) = ident. kind
701
702
&& ident == sym:: compile_error
702
- && let mbe:: TokenTree :: Token ( bang) = bang
703
+ && let mbe:: TokenTree :: Token ( bang, _ ) = bang
703
704
&& let TokenKind :: Not = bang. kind
704
705
&& let mbe:: TokenTree :: Delimited ( .., del) = args
705
706
&& del. delim != Delimiter :: Invisible
@@ -896,7 +897,9 @@ enum TtHandle<'tt> {
896
897
897
898
impl < ' tt > TtHandle < ' tt > {
898
899
fn from_token ( tok : Token ) -> Self {
899
- TtHandle :: Token ( mbe:: TokenTree :: Token ( tok) )
900
+ // `Spacing::Alone` is pessimistic but changing it has no effect on the
901
+ // current test suite.
902
+ TtHandle :: Token ( mbe:: TokenTree :: Token ( tok, Spacing :: Alone ) )
900
903
}
901
904
902
905
fn from_token_kind ( kind : TokenKind , span : Span ) -> Self {
@@ -925,8 +928,8 @@ impl<'tt> Clone for TtHandle<'tt> {
925
928
926
929
// This variant *must* contain a `mbe::TokenTree::Token`, and not
927
930
// any other variant of `mbe::TokenTree`.
928
- TtHandle :: Token ( mbe:: TokenTree :: Token ( tok) ) => {
929
- TtHandle :: Token ( mbe:: TokenTree :: Token ( tok. clone ( ) ) )
931
+ TtHandle :: Token ( mbe:: TokenTree :: Token ( tok, spacing ) ) => {
932
+ TtHandle :: Token ( mbe:: TokenTree :: Token ( tok. clone ( ) , * spacing ) )
930
933
}
931
934
932
935
_ => unreachable ! ( ) ,
@@ -1143,7 +1146,7 @@ fn check_matcher_core<'tt>(
1143
1146
// whereas macros from an external crate have a dummy id.
1144
1147
if def. id != DUMMY_NODE_ID
1145
1148
&& matches ! ( kind, NonterminalKind :: PatParam { inferred: true } )
1146
- && matches ! ( next_token, TokenTree :: Token ( token) if token. kind == BinOp ( token:: BinOpToken :: Or ) )
1149
+ && matches ! ( next_token, TokenTree :: Token ( token, _ ) if token. kind == BinOp ( token:: BinOpToken :: Or ) )
1147
1150
{
1148
1151
// It is suggestion to use pat_param, for example: $x:pat -> $x:pat_param.
1149
1152
let suggestion = quoted_tt_to_string ( & TokenTree :: MetaVarDecl (
@@ -1274,7 +1277,7 @@ enum IsInFollow {
1274
1277
fn is_in_follow ( tok : & mbe:: TokenTree , kind : NonterminalKind ) -> IsInFollow {
1275
1278
use mbe:: TokenTree ;
1276
1279
1277
- if let TokenTree :: Token ( Token { kind : token:: CloseDelim ( _) , .. } ) = * tok {
1280
+ if let TokenTree :: Token ( Token { kind : token:: CloseDelim ( _) , .. } , _ ) = * tok {
1278
1281
// closing a token tree can never be matched by any fragment;
1279
1282
// iow, we always require that `(` and `)` match, etc.
1280
1283
IsInFollow :: Yes
@@ -1293,7 +1296,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
1293
1296
NonterminalKind :: Stmt | NonterminalKind :: Expr => {
1294
1297
const TOKENS : & [ & str ] = & [ "`=>`" , "`,`" , "`;`" ] ;
1295
1298
match tok {
1296
- TokenTree :: Token ( token) => match token. kind {
1299
+ TokenTree :: Token ( token, _ ) => match token. kind {
1297
1300
FatArrow | Comma | Semi => IsInFollow :: Yes ,
1298
1301
_ => IsInFollow :: No ( TOKENS ) ,
1299
1302
} ,
@@ -1303,7 +1306,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
1303
1306
NonterminalKind :: PatParam { .. } => {
1304
1307
const TOKENS : & [ & str ] = & [ "`=>`" , "`,`" , "`=`" , "`|`" , "`if`" , "`in`" ] ;
1305
1308
match tok {
1306
- TokenTree :: Token ( token) => match token. kind {
1309
+ TokenTree :: Token ( token, _ ) => match token. kind {
1307
1310
FatArrow | Comma | Eq | BinOp ( token:: Or ) => IsInFollow :: Yes ,
1308
1311
Ident ( name, IdentIsRaw :: No ) if name == kw:: If || name == kw:: In => {
1309
1312
IsInFollow :: Yes
@@ -1316,7 +1319,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
1316
1319
NonterminalKind :: PatWithOr => {
1317
1320
const TOKENS : & [ & str ] = & [ "`=>`" , "`,`" , "`=`" , "`if`" , "`in`" ] ;
1318
1321
match tok {
1319
- TokenTree :: Token ( token) => match token. kind {
1322
+ TokenTree :: Token ( token, _ ) => match token. kind {
1320
1323
FatArrow | Comma | Eq => IsInFollow :: Yes ,
1321
1324
Ident ( name, IdentIsRaw :: No ) if name == kw:: If || name == kw:: In => {
1322
1325
IsInFollow :: Yes
@@ -1332,7 +1335,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
1332
1335
"`where`" ,
1333
1336
] ;
1334
1337
match tok {
1335
- TokenTree :: Token ( token) => match token. kind {
1338
+ TokenTree :: Token ( token, _ ) => match token. kind {
1336
1339
OpenDelim ( Delimiter :: Brace )
1337
1340
| OpenDelim ( Delimiter :: Bracket )
1338
1341
| Comma
@@ -1369,7 +1372,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
1369
1372
// Explicitly disallow `priv`, on the off chance it comes back.
1370
1373
const TOKENS : & [ & str ] = & [ "`,`" , "an ident" , "a type" ] ;
1371
1374
match tok {
1372
- TokenTree :: Token ( token) => match token. kind {
1375
+ TokenTree :: Token ( token, _ ) => match token. kind {
1373
1376
Comma => IsInFollow :: Yes ,
1374
1377
Ident ( _, IdentIsRaw :: Yes ) => IsInFollow :: Yes ,
1375
1378
Ident ( name, _) if name != kw:: Priv => IsInFollow :: Yes ,
@@ -1395,7 +1398,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow {
1395
1398
1396
1399
fn quoted_tt_to_string ( tt : & mbe:: TokenTree ) -> String {
1397
1400
match tt {
1398
- mbe:: TokenTree :: Token ( token) => pprust:: token_to_string ( token) . into ( ) ,
1401
+ mbe:: TokenTree :: Token ( token, _ ) => pprust:: token_to_string ( token) . into ( ) ,
1399
1402
mbe:: TokenTree :: MetaVar ( _, name) => format ! ( "${name}" ) ,
1400
1403
mbe:: TokenTree :: MetaVarDecl ( _, name, Some ( kind) ) => format ! ( "${name}:{kind}" ) ,
1401
1404
mbe:: TokenTree :: MetaVarDecl ( _, name, None ) => format ! ( "${name}:" ) ,
0 commit comments