@@ -12,7 +12,6 @@ use rustc_macros::HashStable_Generic;
1212use rustc_span:: symbol:: { kw, sym} ;
1313use rustc_span:: symbol:: { Ident , Symbol } ;
1414use rustc_span:: { self , edition:: Edition , Span , DUMMY_SP } ;
15- use std:: borrow:: Cow ;
1615use std:: { fmt, mem} ;
1716
1817#[ derive( Clone , Copy , PartialEq , Encodable , Decodable , Debug , HashStable_Generic ) ]
@@ -227,14 +226,8 @@ pub enum TokenKind {
227226 Literal ( Lit ) ,
228227
229228 /// Identifier token.
230- /// Do not forget about `NtIdent` when you want to match on identifiers.
231- /// It's recommended to use `Token::(ident,uninterpolate,uninterpolated_span)` to
232- /// treat regular and interpolated identifiers in the same way.
233229 Ident ( Symbol , /* is_raw */ bool ) ,
234230 /// Lifetime identifier token.
235- /// Do not forget about `NtLifetime` when you want to match on lifetime identifiers.
236- /// It's recommended to use `Token::(lifetime,uninterpolate,uninterpolated_span)` to
237- /// treat regular and interpolated lifetime identifiers in the same way.
238231 Lifetime ( Symbol ) ,
239232
240233 Interpolated ( Lrc < Nonterminal > ) ,
@@ -364,7 +357,7 @@ impl Token {
364357
365358 /// Returns `true` if the token can appear at the start of an expression.
366359 pub fn can_begin_expr ( & self ) -> bool {
367- match self . uninterpolate ( ) . kind {
360+ match self . kind {
368361 Ident ( name, is_raw) =>
369362 ident_can_begin_expr ( name, self . span , is_raw) , // value name or keyword
370363 OpenDelim ( ..) | // tuple, array or block
@@ -391,7 +384,7 @@ impl Token {
391384
392385 /// Returns `true` if the token can appear at the start of a type.
393386 pub fn can_begin_type ( & self ) -> bool {
394- match self . uninterpolate ( ) . kind {
387+ match self . kind {
395388 Ident ( name, is_raw) =>
396389 ident_can_begin_type ( name, self . span , is_raw) , // type name or keyword
397390 OpenDelim ( Delimiter :: Parenthesis ) | // tuple
@@ -439,7 +432,7 @@ impl Token {
439432 ///
440433 /// Keep this in sync with and `Lit::from_token`, excluding unary negation.
441434 pub fn can_begin_literal_maybe_minus ( & self ) -> bool {
442- match self . uninterpolate ( ) . kind {
435+ match self . kind {
443436 Literal ( ..) | BinOp ( Minus ) => true ,
444437 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
445438 Interpolated ( ref nt) => match & * * nt {
@@ -457,37 +450,18 @@ impl Token {
457450 }
458451 }
459452
460- // A convenience function for matching on identifiers during parsing.
461- // Turns interpolated identifier (`$i: ident`) or lifetime (`$l: lifetime`) token
462- // into the regular identifier or lifetime token it refers to,
463- // otherwise returns the original token.
464- pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
465- match & self . kind {
466- Interpolated ( nt) => match * * nt {
467- NtIdent ( ident, is_raw) => {
468- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
469- }
470- NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
471- _ => Cow :: Borrowed ( self ) ,
472- } ,
473- _ => Cow :: Borrowed ( self ) ,
474- }
475- }
476-
477453 /// Returns an identifier if this token is an identifier.
478454 pub fn ident ( & self ) -> Option < ( Ident , /* is_raw */ bool ) > {
479- let token = self . uninterpolate ( ) ;
480- match token. kind {
481- Ident ( name, is_raw) => Some ( ( Ident :: new ( name, token. span ) , is_raw) ) ,
455+ match self . kind {
456+ Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
482457 _ => None ,
483458 }
484459 }
485460
486461 /// Returns a lifetime identifier if this token is a lifetime.
487462 pub fn lifetime ( & self ) -> Option < Ident > {
488- let token = self . uninterpolate ( ) ;
489- match token. kind {
490- Lifetime ( name) => Some ( Ident :: new ( name, token. span ) ) ,
463+ match self . kind {
464+ Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
491465 _ => None ,
492466 }
493467 }
@@ -521,7 +495,7 @@ impl Token {
521495 /// (which happens while parsing the result of macro expansion)?
522496 pub fn is_whole_expr ( & self ) -> bool {
523497 if let Interpolated ( ref nt) = self . kind
524- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtIdent ( .. ) | NtBlock ( _) = * * nt
498+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
525499 {
526500 return true ;
527501 }
@@ -679,8 +653,6 @@ pub enum Nonterminal {
679653 NtPat ( P < ast:: Pat > ) ,
680654 NtExpr ( P < ast:: Expr > ) ,
681655 NtTy ( P < ast:: Ty > ) ,
682- NtIdent ( Ident , /* is_raw */ bool ) ,
683- NtLifetime ( Ident ) ,
684656 NtLiteral ( P < ast:: Expr > ) ,
685657 /// Stuff inside brackets for attributes
686658 NtMeta ( P < ast:: AttrItem > ) ,
@@ -779,7 +751,6 @@ impl Nonterminal {
779751 NtPat ( pat) => pat. span ,
780752 NtExpr ( expr) | NtLiteral ( expr) => expr. span ,
781753 NtTy ( ty) => ty. span ,
782- NtIdent ( ident, _) | NtLifetime ( ident) => ident. span ,
783754 NtMeta ( attr_item) => attr_item. span ( ) ,
784755 NtPath ( path) => path. span ,
785756 NtVis ( vis) => vis. span ,
@@ -790,11 +761,7 @@ impl Nonterminal {
790761impl PartialEq for Nonterminal {
791762 fn eq ( & self , rhs : & Self ) -> bool {
792763 match ( self , rhs) {
793- ( NtIdent ( ident_lhs, is_raw_lhs) , NtIdent ( ident_rhs, is_raw_rhs) ) => {
794- ident_lhs == ident_rhs && is_raw_lhs == is_raw_rhs
795- }
796- ( NtLifetime ( ident_lhs) , NtLifetime ( ident_rhs) ) => ident_lhs == ident_rhs,
797- // FIXME: Assume that all "complex" nonterminal are not equal, we can't compare them
764+ // FIXME: Assume that all nonterminals are not equal, because we can't compare them
798765 // correctly based on data from AST. This will prevent them from matching each other
799766 // in macros. The comparison will become possible only when each nonterminal has an
800767 // attached token stream from which it was parsed.
@@ -812,12 +779,10 @@ impl fmt::Debug for Nonterminal {
812779 NtPat ( ..) => f. pad ( "NtPat(..)" ) ,
813780 NtExpr ( ..) => f. pad ( "NtExpr(..)" ) ,
814781 NtTy ( ..) => f. pad ( "NtTy(..)" ) ,
815- NtIdent ( ..) => f. pad ( "NtIdent(..)" ) ,
816782 NtLiteral ( ..) => f. pad ( "NtLiteral(..)" ) ,
817783 NtMeta ( ..) => f. pad ( "NtMeta(..)" ) ,
818784 NtPath ( ..) => f. pad ( "NtPath(..)" ) ,
819785 NtVis ( ..) => f. pad ( "NtVis(..)" ) ,
820- NtLifetime ( ..) => f. pad ( "NtLifetime(..)" ) ,
821786 }
822787 }
823788}
0 commit comments