11pub use BinOpToken :: * ;
22pub use LitKind :: * ;
3- pub use Nonterminal :: * ;
43pub use TokenKind :: * ;
54
65use crate :: ast;
7- use crate :: ptr:: P ;
86use crate :: util:: case:: Case ;
97
10- use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
11- use rustc_data_structures:: sync:: Lrc ;
128use rustc_macros:: { Decodable , Encodable , HashStable_Generic } ;
139use rustc_span:: symbol:: { kw, sym} ;
1410#[ allow( clippy:: useless_attribute) ] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
@@ -282,9 +278,7 @@ impl From<IdentIsRaw> for bool {
282278 }
283279}
284280
285- // SAFETY: due to the `Clone` impl below, all fields of all variants other than
286- // `Interpolated` must impl `Copy`.
287- #[ derive( PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
281+ #[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
288282pub enum TokenKind {
289283 /* Expression-operator symbols. */
290284 /// `=`
@@ -373,21 +367,6 @@ pub enum TokenKind {
373367 /// the `lifetime` metavariable in the macro's RHS.
374368 NtLifetime ( Ident ) ,
375369
376- /// An embedded AST node, as produced by a macro. This only exists for
377- /// historical reasons. We'd like to get rid of it, for multiple reasons.
378- /// - It's conceptually very strange. Saying a token can contain an AST
379- /// node is like saying, in natural language, that a word can contain a
380- /// sentence.
381- /// - It requires special handling in a bunch of places in the parser.
382- /// - It prevents `Token` from implementing `Copy`.
383- /// It adds complexity and likely slows things down. Please don't add new
384- /// occurrences of this token kind!
385- ///
386- /// The span in the surrounding `Token` is that of the metavariable in the
387- /// macro's RHS. The span within the Nonterminal is that of the fragment
388- /// passed to the macro at the call site.
389- Interpolated ( Lrc < Nonterminal > ) ,
390-
391370 /// A doc comment token.
392371 /// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
393372 /// similarly to symbols in string literal tokens.
@@ -397,19 +376,6 @@ pub enum TokenKind {
397376 Eof ,
398377}
399378
400- impl Clone for TokenKind {
401- fn clone ( & self ) -> Self {
402- // `TokenKind` would impl `Copy` if it weren't for `Interpolated`. So
403- // for all other variants, this implementation of `clone` is just like
404- // a copy. This is faster than the `derive(Clone)` version which has a
405- // separate path for every variant.
406- match self {
407- Interpolated ( nt) => Interpolated ( nt. clone ( ) ) ,
408- _ => unsafe { std:: ptr:: read ( self ) } ,
409- }
410- }
411- }
412-
413379#[ derive( Clone , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
414380pub struct Token {
415381 pub kind : TokenKind ,
@@ -496,7 +462,6 @@ impl Token {
496462 pub fn uninterpolated_span ( & self ) -> Span {
497463 match self . kind {
498464 NtIdent ( ident, _) | NtLifetime ( ident) => ident. span ,
499- Interpolated ( ref nt) => nt. use_span ( ) ,
500465 _ => self . span ,
501466 }
502467 }
@@ -514,7 +479,7 @@ impl Token {
514479 }
515480
516481 OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | DocComment ( ..) | Ident ( ..)
517- | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | Eof => false ,
482+ | NtIdent ( ..) | Lifetime ( ..) | NtLifetime ( ..) | Eof => false ,
518483 }
519484 }
520485
@@ -542,7 +507,6 @@ impl Token {
542507 PathSep | // global path
543508 Lifetime ( ..) | // labeled loop
544509 Pound => true , // expression attributes
545- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
546510 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
547511 NonterminalKind :: Block |
548512 NonterminalKind :: Expr |
@@ -569,7 +533,6 @@ impl Token {
569533 | DotDot | DotDotDot | DotDotEq // ranges
570534 | Lt | BinOp ( Shl ) // associated path
571535 | PathSep => true , // global path
572- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
573536 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
574537 NonterminalKind :: Block |
575538 NonterminalKind :: PatParam { .. } |
@@ -610,7 +573,6 @@ impl Token {
610573 pub fn can_begin_const_arg ( & self ) -> bool {
611574 match self . kind {
612575 OpenDelim ( Delimiter :: Brace ) => true ,
613- Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
614576 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
615577 NonterminalKind :: Expr | NonterminalKind :: Block | NonterminalKind :: Literal ,
616578 ) ) ) => true ,
@@ -733,31 +695,20 @@ impl Token {
733695 /// That is, is this a pre-parsed expression dropped into the token stream
734696 /// (which happens while parsing the result of macro expansion)?
735697 pub fn is_metavar_expr ( & self ) -> bool {
736- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
737- if let Interpolated ( nt) = & self . kind
738- && let NtBlock ( _) = & * * nt
739- {
740- true
741- } else if matches ! (
698+ matches ! (
742699 self . is_metavar_seq( ) ,
743- Some ( NonterminalKind :: Expr | NonterminalKind :: Literal | NonterminalKind :: Path )
744- ) {
745- true
746- } else {
747- false
748- }
700+ Some (
701+ NonterminalKind :: Expr
702+ | NonterminalKind :: Literal
703+ | NonterminalKind :: Path
704+ | NonterminalKind :: Block
705+ )
706+ )
749707 }
750708
751- /// Is the token an interpolated block (`$b:block`)?
752- pub fn is_whole_block ( & self ) -> bool {
753- #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
754- if let Interpolated ( nt) = & self . kind
755- && let NtBlock ( ..) = & * * nt
756- {
757- return true ;
758- }
759-
760- false
709+ /// Are we at a block from a metavar (`$b:block`)?
710+ pub fn is_metavar_block ( & self ) -> bool {
711+ matches ! ( self . is_metavar_seq( ) , Some ( NonterminalKind :: Block ) )
761712 }
762713
763714 /// Returns `true` if the token is either the `mut` or `const` keyword.
@@ -782,7 +733,8 @@ impl Token {
782733 self . is_non_raw_ident_where ( |id| id. name == kw)
783734 }
784735
785- /// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this token is an identifier equal to `kw` ignoring the case.
736+ /// Returns `true` if the token is a given keyword, `kw` or if `case` is `Insensitive` and this
737+ /// token is an identifier equal to `kw` ignoring the case.
786738 pub fn is_keyword_case ( & self , kw : Symbol , case : Case ) -> bool {
787739 self . is_keyword ( kw)
788740 || ( case == Case :: Insensitive
@@ -903,7 +855,7 @@ impl Token {
903855 Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq ( ..) | At | DotDotDot
904856 | DotDotEq | Comma | Semi | PathSep | RArrow | LArrow | FatArrow | Pound | Dollar
905857 | Question | OpenDelim ( ..) | CloseDelim ( ..) | Literal ( ..) | Ident ( ..) | NtIdent ( ..)
906- | Lifetime ( ..) | NtLifetime ( ..) | Interpolated ( .. ) | DocComment ( ..) | Eof => {
858+ | Lifetime ( ..) | NtLifetime ( ..) | DocComment ( ..) | Eof => {
907859 return None ;
908860 }
909861 } ;
@@ -919,12 +871,6 @@ impl PartialEq<TokenKind> for Token {
919871 }
920872}
921873
922- #[ derive( Clone , Encodable , Decodable ) ]
923- /// For interpolation during macro expansion.
924- pub enum Nonterminal {
925- NtBlock ( P < ast:: Block > ) ,
926- }
927-
928874#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
929875pub enum NonterminalKind {
930876 Item ,
@@ -1003,47 +949,6 @@ impl fmt::Display for NonterminalKind {
1003949 }
1004950}
1005951
1006- impl Nonterminal {
1007- pub fn use_span ( & self ) -> Span {
1008- match self {
1009- NtBlock ( block) => block. span ,
1010- }
1011- }
1012-
1013- pub fn descr ( & self ) -> & ' static str {
1014- match self {
1015- NtBlock ( ..) => "block" ,
1016- }
1017- }
1018- }
1019-
1020- impl PartialEq for Nonterminal {
1021- fn eq ( & self , _rhs : & Self ) -> bool {
1022- // FIXME: Assume that all nonterminals are not equal, we can't compare them
1023- // correctly based on data from AST. This will prevent them from matching each other
1024- // in macros. The comparison will become possible only when each nonterminal has an
1025- // attached token stream from which it was parsed.
1026- false
1027- }
1028- }
1029-
1030- impl fmt:: Debug for Nonterminal {
1031- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1032- match * self {
1033- NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1034- }
1035- }
1036- }
1037-
1038- impl < CTX > HashStable < CTX > for Nonterminal
1039- where
1040- CTX : crate :: HashStableContext ,
1041- {
1042- fn hash_stable ( & self , _hcx : & mut CTX , _hasher : & mut StableHasher ) {
1043- panic ! ( "interpolated tokens should not be present in the HIR" )
1044- }
1045- }
1046-
1047952// Some types are used a lot. Make sure they don't unintentionally get bigger.
1048953#[ cfg( target_pointer_width = "64" ) ]
1049954mod size_asserts {
@@ -1052,7 +957,6 @@ mod size_asserts {
1052957 // tidy-alphabetical-start
1053958 static_assert_size ! ( Lit , 12 ) ;
1054959 static_assert_size ! ( LitKind , 2 ) ;
1055- static_assert_size ! ( Nonterminal , 8 ) ;
1056960 static_assert_size ! ( Token , 24 ) ;
1057961 static_assert_size ! ( TokenKind , 16 ) ;
1058962 // tidy-alphabetical-end
0 commit comments