@@ -318,11 +318,20 @@ pub enum TokenKind {
318318     /// It's recommended to use `Token::(ident,uninterpolate,uninterpolated_span)` to 
319319     /// treat regular and interpolated identifiers in the same way. 
320320     Ident ( Symbol ,  IdentIsRaw ) , 
321+     /// This identifier (and its span) is the identifier passed to the 
322+      /// declarative macro. The span in the surrounding `Token` is the span of 
323+      /// the `ident` metavariable in the macro's RHS. 
324+      NtIdent ( Ident ,  IdentIsRaw ) , 
325+ 
321326    /// Lifetime identifier token. 
322-      /// Do not forget about `NtLifetime ` when you want to match on lifetime identifiers. 
327+      /// Do not forget about `InterpolatedLIfetime ` when you want to match on lifetime identifiers. 
323328     /// It's recommended to use `Token::(lifetime,uninterpolate,uninterpolated_span)` to 
324329     /// treat regular and interpolated lifetime identifiers in the same way. 
325330     Lifetime ( Symbol ) , 
331+     /// This identifier (and its span) is the lifetime passed to the 
332+      /// declarative macro. The span in the surrounding `Token` is the span of 
333+      /// the `lifetime` metavariable in the macro's RHS. 
334+      NtLifetime ( Ident ) , 
326335
327336    /// An embedded AST node, as produced by a macro. This only exists for 
328337     /// historical reasons. We'd like to get rid of it, for multiple reasons. 
@@ -444,8 +453,9 @@ impl Token {
444453     /// Note that keywords are also identifiers, so they should use this 
445454     /// if they keep spans or perform edition checks. 
446455     pub  fn  uninterpolated_span ( & self )  -> Span  { 
447-         match  & self . kind  { 
448-             Interpolated ( nt)  => nt. use_span ( ) , 
456+         match  self . kind  { 
457+             NtIdent ( ident,  _)  | NtLifetime ( ident)  => ident. span , 
458+             Interpolated ( ref  nt)  => nt. use_span ( ) , 
449459            _ => self . span , 
450460        } 
451461    } 
@@ -463,7 +473,7 @@ impl Token {
463473            } 
464474
465475            OpenDelim ( ..)  | CloseDelim ( ..)  | Literal ( ..)  | DocComment ( ..)  | Ident ( ..) 
466-             | Lifetime ( ..)  | Interpolated ( ..)  | Eof  => false , 
476+             | NtIdent ( .. )  |  Lifetime ( .. )  |  NtLifetime ( ..)  | Interpolated ( ..)  | Eof  => false , 
467477        } 
468478    } 
469479
@@ -613,14 +623,9 @@ impl Token {
613623     /// into the regular identifier or lifetime token it refers to, 
614624     /// otherwise returns the original token. 
615625     pub  fn  uninterpolate ( & self )  -> Cow < ' _ ,  Token >  { 
616-         match  & self . kind  { 
617-             Interpolated ( nt)  => match  & * * nt { 
618-                 NtIdent ( ident,  is_raw)  => { 
619-                     Cow :: Owned ( Token :: new ( Ident ( ident. name ,  * is_raw) ,  ident. span ) ) 
620-                 } 
621-                 NtLifetime ( ident)  => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) ,  ident. span ) ) , 
622-                 _ => Cow :: Borrowed ( self ) , 
623-             } , 
626+         match  self . kind  { 
627+             NtIdent ( ident,  is_raw)  => Cow :: Owned ( Token :: new ( Ident ( ident. name ,  is_raw) ,  ident. span ) ) , 
628+             NtLifetime ( ident)  => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) ,  ident. span ) ) , 
624629            _ => Cow :: Borrowed ( self ) , 
625630        } 
626631    } 
@@ -629,12 +634,9 @@ impl Token {
629634     #[ inline]  
630635    pub  fn  ident ( & self )  -> Option < ( Ident ,  IdentIsRaw ) >  { 
631636        // We avoid using `Token::uninterpolate` here because it's slow. 
632-         match  & self . kind  { 
633-             & Ident ( name,  is_raw)  => Some ( ( Ident :: new ( name,  self . span ) ,  is_raw) ) , 
634-             Interpolated ( nt)  => match  & * * nt { 
635-                 NtIdent ( ident,  is_raw)  => Some ( ( * ident,  * is_raw) ) , 
636-                 _ => None , 
637-             } , 
637+         match  self . kind  { 
638+             Ident ( name,  is_raw)  => Some ( ( Ident :: new ( name,  self . span ) ,  is_raw) ) , 
639+             NtIdent ( ident,  is_raw)  => Some ( ( ident,  is_raw) ) , 
638640            _ => None , 
639641        } 
640642    } 
@@ -643,12 +645,9 @@ impl Token {
643645     #[ inline]  
644646    pub  fn  lifetime ( & self )  -> Option < Ident >  { 
645647        // We avoid using `Token::uninterpolate` here because it's slow. 
646-         match  & self . kind  { 
647-             & Lifetime ( name)  => Some ( Ident :: new ( name,  self . span ) ) , 
648-             Interpolated ( nt)  => match  & * * nt { 
649-                 NtLifetime ( ident)  => Some ( * ident) , 
650-                 _ => None , 
651-             } , 
648+         match  self . kind  { 
649+             Lifetime ( name)  => Some ( Ident :: new ( name,  self . span ) ) , 
650+             NtLifetime ( ident)  => Some ( ident) , 
652651            _ => None , 
653652        } 
654653    } 
@@ -837,8 +836,10 @@ impl Token {
837836
838837            Le  | EqEq  | Ne  | Ge  | AndAnd  | OrOr  | Tilde  | BinOpEq ( ..)  | At  | DotDotDot 
839838            | DotDotEq  | Comma  | Semi  | PathSep  | RArrow  | LArrow  | FatArrow  | Pound  | Dollar 
840-             | Question  | OpenDelim ( ..)  | CloseDelim ( ..)  | Literal ( ..)  | Ident ( ..) 
841-             | Lifetime ( ..)  | Interpolated ( ..)  | DocComment ( ..)  | Eof  => return  None , 
839+             | Question  | OpenDelim ( ..)  | CloseDelim ( ..)  | Literal ( ..)  | Ident ( ..)  | NtIdent ( ..) 
840+             | Lifetime ( ..)  | NtLifetime ( ..)  | Interpolated ( ..)  | DocComment ( ..)  | Eof  => { 
841+                 return  None ; 
842+             } 
842843        } ; 
843844
844845        Some ( Token :: new ( kind,  self . span . to ( joint. span ) ) ) 
@@ -861,9 +862,6 @@ pub enum Nonterminal {
861862    NtPat ( P < ast:: Pat > ) , 
862863    NtExpr ( P < ast:: Expr > ) , 
863864    NtTy ( P < ast:: Ty > ) , 
864-     /// The span is for the identifier argument passed to the macro. 
865-      NtIdent ( Ident ,  IdentIsRaw ) , 
866-     NtLifetime ( Ident ) , 
867865    NtLiteral ( P < ast:: Expr > ) , 
868866    /// Stuff inside brackets for attributes 
869867     NtMeta ( P < ast:: AttrItem > ) , 
@@ -958,7 +956,6 @@ impl Nonterminal {
958956            NtPat ( pat)  => pat. span , 
959957            NtExpr ( expr)  | NtLiteral ( expr)  => expr. span , 
960958            NtTy ( ty)  => ty. span , 
961-             NtIdent ( ident,  _)  | NtLifetime ( ident)  => ident. span , 
962959            NtMeta ( attr_item)  => attr_item. span ( ) , 
963960            NtPath ( path)  => path. span , 
964961            NtVis ( vis)  => vis. span , 
@@ -974,8 +971,6 @@ impl Nonterminal {
974971            NtExpr ( ..)  => "expression" , 
975972            NtLiteral ( ..)  => "literal" , 
976973            NtTy ( ..)  => "type" , 
977-             NtIdent ( ..)  => "identifier" , 
978-             NtLifetime ( ..)  => "lifetime" , 
979974            NtMeta ( ..)  => "attribute" , 
980975            NtPath ( ..)  => "path" , 
981976            NtVis ( ..)  => "visibility" , 
@@ -984,18 +979,12 @@ impl Nonterminal {
984979} 
985980
986981impl  PartialEq  for  Nonterminal  { 
987-     fn  eq ( & self ,  rhs :  & Self )  -> bool  { 
988-         match  ( self ,  rhs)  { 
989-             ( NtIdent ( ident_lhs,  is_raw_lhs) ,  NtIdent ( ident_rhs,  is_raw_rhs) )  => { 
990-                 ident_lhs == ident_rhs && is_raw_lhs == is_raw_rhs
991-             } 
992-             ( NtLifetime ( ident_lhs) ,  NtLifetime ( ident_rhs) )  => ident_lhs == ident_rhs, 
993-             // FIXME: Assume that all "complex" nonterminal are not equal, we can't compare them 
994-             // correctly based on data from AST. This will prevent them from matching each other 
995-             // in macros. The comparison will become possible only when each nonterminal has an 
996-             // attached token stream from which it was parsed. 
997-             _ => false , 
998-         } 
982+     fn  eq ( & self ,  _rhs :  & Self )  -> bool  { 
983+         // FIXME: Assume that all nonterminals are not equal, we can't compare them 
984+         // correctly based on data from AST. This will prevent them from matching each other 
985+         // in macros. The comparison will become possible only when each nonterminal has an 
986+         // attached token stream from which it was parsed. 
987+         false 
999988    } 
1000989} 
1001990
@@ -1008,12 +997,10 @@ impl fmt::Debug for Nonterminal {
1008997            NtPat ( ..)  => f. pad ( "NtPat(..)" ) , 
1009998            NtExpr ( ..)  => f. pad ( "NtExpr(..)" ) , 
1010999            NtTy ( ..)  => f. pad ( "NtTy(..)" ) , 
1011-             NtIdent ( ..)  => f. pad ( "NtIdent(..)" ) , 
10121000            NtLiteral ( ..)  => f. pad ( "NtLiteral(..)" ) , 
10131001            NtMeta ( ..)  => f. pad ( "NtMeta(..)" ) , 
10141002            NtPath ( ..)  => f. pad ( "NtPath(..)" ) , 
10151003            NtVis ( ..)  => f. pad ( "NtVis(..)" ) , 
1016-             NtLifetime ( ..)  => f. pad ( "NtLifetime(..)" ) , 
10171004        } 
10181005    } 
10191006} 
0 commit comments