11use std:: borrow:: Cow ;
22use std:: fmt;
3- use std:: sync:: Arc ;
43
54pub use LitKind :: * ;
6- pub use Nonterminal :: * ;
75pub use NtExprKind :: * ;
86pub use NtPatKind :: * ;
97pub use TokenKind :: * ;
10- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
118use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
129use rustc_span:: edition:: Edition ;
1310use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span , kw, sym} ;
@@ -16,7 +13,6 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, kw, sym};
1613use rustc_span:: { Ident , Symbol } ;
1714
1815use crate :: ast;
19- use crate :: ptr:: P ;
2016use crate :: util:: case:: Case ;
2117
2218#[ derive( Clone , Copy , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
@@ -34,10 +30,6 @@ pub enum InvisibleOrigin {
3430 // Converted from `proc_macro::Delimiter` in
3531 // `proc_macro::Delimiter::to_internal`, i.e. returned by a proc macro.
3632 ProcMacro ,
37-
38- // Converted from `TokenKind::Interpolated` in
39- // `TokenStream::flatten_token`. Treated similarly to `ProcMacro`.
40- FlattenToken ,
4133}
4234
4335impl PartialEq for InvisibleOrigin {
@@ -134,9 +126,7 @@ impl Delimiter {
134126 match self {
135127 Delimiter :: Parenthesis | Delimiter :: Bracket | Delimiter :: Brace => false ,
136128 Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( _) ) => false ,
137- Delimiter :: Invisible ( InvisibleOrigin :: FlattenToken | InvisibleOrigin :: ProcMacro ) => {
138- true
139- }
129+ Delimiter :: Invisible ( InvisibleOrigin :: ProcMacro ) => true ,
140130 }
141131 }
142132
@@ -337,9 +327,7 @@ impl From<IdentIsRaw> for bool {
337327 }
338328}
339329
340- // SAFETY: due to the `Clone` impl below, all fields of all variants other than
341- // `Interpolated` must impl `Copy`.
342- #[ derive( PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
330+ #[ derive( Clone , Copy , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
343331pub enum TokenKind {
344332 /* Expression-operator symbols. */
345333 /// `=`
@@ -468,21 +456,6 @@ pub enum TokenKind {
468456 /// the `lifetime` metavariable in the macro's RHS.
469457 NtLifetime ( Ident , IdentIsRaw ) ,
470458
471- /// An embedded AST node, as produced by a macro. This only exists for
472- /// historical reasons. We'd like to get rid of it, for multiple reasons.
473- /// - It's conceptually very strange. Saying a token can contain an AST
474- /// node is like saying, in natural language, that a word can contain a
475- /// sentence.
476- /// - It requires special handling in a bunch of places in the parser.
477- /// - It prevents `Token` from implementing `Copy`.
478- /// It adds complexity and likely slows things down. Please don't add new
479- /// occurrences of this token kind!
480- ///
481- /// The span in the surrounding `Token` is that of the metavariable in the
482- /// macro's RHS. The span within the Nonterminal is that of the fragment
483- /// passed to the macro at the call site.
484- Interpolated ( Arc < Nonterminal > ) ,
485-
486459 /// A doc comment token.
487460 /// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
488461 /// similarly to symbols in string literal tokens.
@@ -492,20 +465,7 @@ pub enum TokenKind {
492465 Eof ,
493466}
494467
495- impl Clone for TokenKind {
496- fn clone ( & self ) -> Self {
497- // `TokenKind` would impl `Copy` if it weren't for `Interpolated`. So
498- // for all other variants, this implementation of `clone` is just like
499- // a copy. This is faster than the `derive(Clone)` version which has a
500- // separate path for every variant.
501- match self {
502- Interpolated ( nt) => Interpolated ( Arc :: clone ( nt) ) ,
503- _ => unsafe { std:: ptr:: read ( self ) } ,
504- }
505- }
506- }
507-
508- #[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
468+ #[ derive( Clone , Copy , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
509469pub struct Token {
510470 pub kind : TokenKind ,
511471 pub span : Span ,
@@ -600,7 +560,7 @@ impl Token {
600560 | FatArrow | Pound | Dollar | Question | SingleQuote => true ,
601561
602562 OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | DocComment ( ..) | Ident ( ..)
603- | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | Eof => false ,
563+ | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Eof => false ,
604564 }
605565 }
606566
@@ -631,7 +591,6 @@ impl Token {
631591 PathSep | // global path
632592 Lifetime ( ..) | // labeled loop
633593 Pound => true , // expression attributes
634- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
635594 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
636595 MetaVarKind :: Block |
637596 MetaVarKind :: Expr { .. } |
@@ -703,7 +662,6 @@ impl Token {
703662 match self . kind {
704663 OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | Minus => true ,
705664 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
706- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
707665 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
708666 MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
709667 ) ) ) => true ,
@@ -831,31 +789,20 @@ impl Token {
831789 /// Is this a pre-parsed expression dropped into the token stream
832790 /// (which happens while parsing the result of macro expansion)?
833791 pub fn is_metavar_expr ( & self ) -> bool {
834- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
835- if let Interpolated ( nt) = & self . kind
836- && let NtBlock ( _) = & * * nt
837- {
838- true
839- } else if matches ! (
792+ matches ! (
840793 self . is_metavar_seq( ) ,
841- Some ( MetaVarKind :: Expr { .. } | MetaVarKind :: Literal | MetaVarKind :: Path )
842- ) {
843- true
844- } else {
845- matches ! ( self . is_metavar_seq( ) , Some ( MetaVarKind :: Path ) )
846- }
794+ Some (
795+ MetaVarKind :: Expr { .. }
796+ | MetaVarKind :: Literal
797+ | MetaVarKind :: Path
798+ | MetaVarKind :: Block
799+ )
800+ )
847801 }
848802
849- /// Is the token an interpolated block (`$b:block`)?
850- pub fn is_whole_block ( & self ) -> bool {
851- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
852- if let Interpolated ( nt) = & self . kind
853- && let NtBlock ( ..) = & * * nt
854- {
855- return true ;
856- }
857-
858- false
803+ /// Are we at a block from a metavar (`$b:block`)?
804+ pub fn is_metavar_block ( & self ) -> bool {
805+ matches ! ( self . is_metavar_seq( ) , Some ( MetaVarKind :: Block ) )
859806 }
860807
861808 /// Returns `true` if the token is either the `mut` or `const` keyword.
@@ -1024,7 +971,7 @@ impl Token {
1024971 | PercentEq | CaretEq | AndEq | OrEq | ShlEq | ShrEq | At | DotDotDot | DotDotEq
1025972 | Comma | Semi | PathSep | RArrow | LArrow | FatArrow | Pound | Dollar | Question
1026973 | OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | Ident ( ..) | NtIdent ( ..)
1027- | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | DocComment ( ..) | Eof ,
974+ | Lifetime ( ..) | NtLifetime ( ..) | DocComment ( ..) | Eof ,
1028975 _,
1029976 ) => {
1030977 return None ;
@@ -1063,12 +1010,6 @@ pub enum NtExprKind {
10631010 Expr2021 { inferred : bool } ,
10641011}
10651012
1066- #[ derive( Clone , Encodable , Decodable ) ]
1067- /// For interpolation during macro expansion.
1068- pub enum Nonterminal {
1069- NtBlock ( P < ast:: Block > ) ,
1070- }
1071-
10721013#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
10731014pub enum NonterminalKind {
10741015 Item ,
@@ -1152,47 +1093,6 @@ impl fmt::Display for NonterminalKind {
11521093 }
11531094}
11541095
1155- impl Nonterminal {
1156- pub fn use_span ( & self ) -> Span {
1157- match self {
1158- NtBlock ( block) => block. span ,
1159- }
1160- }
1161-
1162- pub fn descr ( & self ) -> & ' static str {
1163- match self {
1164- NtBlock ( ..) => "block" ,
1165- }
1166- }
1167- }
1168-
1169- impl PartialEq for Nonterminal {
1170- fn eq ( & self , _rhs : & Self ) -> bool {
1171- // FIXME: Assume that all nonterminals are not equal, we can't compare them
1172- // correctly based on data from AST. This will prevent them from matching each other
1173- // in macros. The comparison will become possible only when each nonterminal has an
1174- // attached token stream from which it was parsed.
1175- false
1176- }
1177- }
1178-
1179- impl fmt:: Debug for Nonterminal {
1180- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1181- match * self {
1182- NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1183- }
1184- }
1185- }
1186-
1187- impl < CTX > HashStable < CTX > for Nonterminal
1188- where
1189- CTX : crate :: HashStableContext ,
1190- {
1191- fn hash_stable ( & self , _hcx : & mut CTX , _hasher : & mut StableHasher ) {
1192- panic ! ( "interpolated tokens should not be present in the HIR" )
1193- }
1194- }
1195-
11961096// Some types are used a lot. Make sure they don't unintentionally get bigger.
11971097#[ cfg( target_pointer_width = "64" ) ]
11981098mod size_asserts {
@@ -1202,7 +1102,6 @@ mod size_asserts {
12021102 // tidy-alphabetical-start
12031103 static_assert_size ! ( Lit , 12 ) ;
12041104 static_assert_size ! ( LitKind , 2 ) ;
1205- static_assert_size ! ( Nonterminal , 8 ) ;
12061105 static_assert_size ! ( Token , 24 ) ;
12071106 static_assert_size ! ( TokenKind , 16 ) ;
12081107 // tidy-alphabetical-end
0 commit comments