@@ -182,6 +182,15 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool {
182182 . contains ( & name)
183183}
184184
185+ /// A hack used to pass AST fragments to attribute and derive macros
186+ /// as a single nonterminal token instead of a token stream.
187+ /// FIXME: It needs to be removed, but there are some compatibility issues (see #73345).
188+ #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable , Debug , HashStable_Generic ) ]
189+ pub enum FlattenGroup {
190+ Yes ,
191+ No ,
192+ }
193+
185194#[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable , Debug , HashStable_Generic ) ]
186195pub enum TokenKind {
187196 /* Expression-operator symbols. */
@@ -236,7 +245,7 @@ pub enum TokenKind {
236245 /// treat regular and interpolated lifetime identifiers in the same way.
237246 Lifetime ( Symbol ) ,
238247
239- Interpolated ( Lrc < Nonterminal > ) ,
248+ Interpolated ( Lrc < Nonterminal > , FlattenGroup ) ,
240249
241250 // Can be expanded into several tokens.
242251 /// A doc comment.
@@ -343,7 +352,7 @@ impl Token {
343352 /// if they keep spans or perform edition checks.
344353 pub fn uninterpolated_span ( & self ) -> Span {
345354 match & self . kind {
346- Interpolated ( nt) => nt. span ( ) ,
355+ Interpolated ( nt, _ ) => nt. span ( ) ,
347356 _ => self . span ,
348357 }
349358 }
@@ -382,7 +391,7 @@ impl Token {
382391 ModSep | // global path
383392 Lifetime ( ..) | // labeled loop
384393 Pound => true , // expression attributes
385- Interpolated ( ref nt) => match * * nt {
394+ Interpolated ( ref nt, _ ) => match * * nt {
386395 NtLiteral ( ..) |
387396 NtExpr ( ..) |
388397 NtBlock ( ..) |
@@ -408,7 +417,7 @@ impl Token {
408417 Lifetime ( ..) | // lifetime bound in trait object
409418 Lt | BinOp ( Shl ) | // associated path
410419 ModSep => true , // global path
411- Interpolated ( ref nt) => match * * nt {
420+ Interpolated ( ref nt, _ ) => match * * nt {
412421 NtTy ( ..) | NtPath ( ..) => true ,
413422 _ => false ,
414423 } ,
@@ -420,7 +429,7 @@ impl Token {
420429 pub fn can_begin_const_arg ( & self ) -> bool {
421430 match self . kind {
422431 OpenDelim ( Brace ) => true ,
423- Interpolated ( ref nt) => match * * nt {
432+ Interpolated ( ref nt, _ ) => match * * nt {
424433 NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) => true ,
425434 _ => false ,
426435 } ,
@@ -455,7 +464,7 @@ impl Token {
455464 match self . uninterpolate ( ) . kind {
456465 Literal ( ..) | BinOp ( Minus ) => true ,
457466 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
458- Interpolated ( ref nt) => match & * * nt {
467+ Interpolated ( ref nt, _ ) => match & * * nt {
459468 NtLiteral ( _) => true ,
460469 NtExpr ( e) => match & e. kind {
461470 ast:: ExprKind :: Lit ( _) => true ,
@@ -476,7 +485,7 @@ impl Token {
476485 // otherwise returns the original token.
477486 pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
478487 match & self . kind {
479- Interpolated ( nt) => match * * nt {
488+ Interpolated ( nt, _ ) => match * * nt {
480489 NtIdent ( ident, is_raw) => {
481490 Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
482491 }
@@ -523,7 +532,7 @@ impl Token {
523532
524533 /// Returns `true` if the token is an interpolated path.
525534 fn is_path ( & self ) -> bool {
526- if let Interpolated ( ref nt) = self . kind {
535+ if let Interpolated ( ref nt, _ ) = self . kind {
527536 if let NtPath ( ..) = * * nt {
528537 return true ;
529538 }
@@ -535,7 +544,7 @@ impl Token {
535544 /// That is, is this a pre-parsed expression dropped into the token stream
536545 /// (which happens while parsing the result of macro expansion)?
537546 pub fn is_whole_expr ( & self ) -> bool {
538- if let Interpolated ( ref nt) = self . kind {
547+ if let Interpolated ( ref nt, _ ) = self . kind {
539548 if let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtIdent ( ..) | NtBlock ( _) = * * nt {
540549 return true ;
541550 }
@@ -546,7 +555,7 @@ impl Token {
546555
547556 // Is the token an interpolated block (`$b:block`)?
548557 pub fn is_whole_block ( & self ) -> bool {
549- if let Interpolated ( ref nt) = self . kind {
558+ if let Interpolated ( ref nt, _ ) = self . kind {
550559 if let NtBlock ( ..) = * * nt {
551560 return true ;
552561 }
@@ -724,7 +733,7 @@ impl Token {
724733 b == d && ( a == c || a == kw:: DollarCrate || c == kw:: DollarCrate )
725734 }
726735
727- ( & Interpolated ( _ ) , & Interpolated ( _ ) ) => false ,
736+ ( & Interpolated ( .. ) , & Interpolated ( .. ) ) => false ,
728737
729738 _ => panic ! ( "forgot to add a token?" ) ,
730739 }
0 commit comments