@@ -110,7 +110,7 @@ impl Lit {
110110 Ident ( name, false ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
111111 Literal ( token_lit) => Some ( token_lit) ,
112112 Interpolated ( ref nt)
113- if let NtExpr ( expr) | NtLiteral ( expr) = & * * nt
113+ if let NtExpr ( expr) | NtLiteral ( expr) = & nt . 0
114114 && let ast:: ExprKind :: Lit ( token_lit) = expr. kind =>
115115 {
116116 Some ( token_lit)
@@ -314,7 +314,7 @@ pub enum TokenKind {
314314 /// - It prevents `Token` from implementing `Copy`.
315315 /// It adds complexity and likely slows things down. Please don't add new
316316 /// occurrences of this token kind!
317- Interpolated ( Lrc < Nonterminal > ) ,
317+ Interpolated ( Lrc < ( Nonterminal , Span ) > ) ,
318318
319319 /// A doc comment token.
320320 /// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
@@ -422,7 +422,7 @@ impl Token {
422422 /// if they keep spans or perform edition checks.
423423 pub fn uninterpolated_span ( & self ) -> Span {
424424 match & self . kind {
425- Interpolated ( nt) => nt. span ( ) ,
425+ Interpolated ( nt) => nt. 0 . use_span ( ) ,
426426 _ => self . span ,
427427 }
428428 }
@@ -465,7 +465,7 @@ impl Token {
465465 ModSep | // global path
466466 Lifetime ( ..) | // labeled loop
467467 Pound => true , // expression attributes
468- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
468+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
469469 NtExpr ( ..) |
470470 NtBlock ( ..) |
471471 NtPath ( ..) ) ,
@@ -489,7 +489,7 @@ impl Token {
489489 | DotDot | DotDotDot | DotDotEq // ranges
490490 | Lt | BinOp ( Shl ) // associated path
491491 | ModSep => true , // global path
492- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
492+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
493493 NtPat ( ..) |
494494 NtBlock ( ..) |
495495 NtPath ( ..) ) ,
@@ -512,7 +512,7 @@ impl Token {
512512 Lifetime ( ..) | // lifetime bound in trait object
513513 Lt | BinOp ( Shl ) | // associated path
514514 ModSep => true , // global path
515- Interpolated ( ref nt) => matches ! ( * * nt , NtTy ( ..) | NtPath ( ..) ) ,
515+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
516516 // For anonymous structs or unions, which only appear in specific positions
517517 // (type of struct fields or union fields), we don't consider them as regular types
518518 _ => false ,
@@ -523,7 +523,7 @@ impl Token {
523523 pub fn can_begin_const_arg ( & self ) -> bool {
524524 match self . kind {
525525 OpenDelim ( Delimiter :: Brace ) => true ,
526- Interpolated ( ref nt) => matches ! ( * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
526+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
527527 _ => self . can_begin_literal_maybe_minus ( ) ,
528528 }
529529 }
@@ -577,7 +577,7 @@ impl Token {
577577 match self . uninterpolate ( ) . kind {
578578 Literal ( ..) | BinOp ( Minus ) => true ,
579579 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
580- Interpolated ( ref nt) => match & * * nt {
580+ Interpolated ( ref nt) => match & nt . 0 {
581581 NtLiteral ( _) => true ,
582582 NtExpr ( e) => match & e. kind {
583583 ast:: ExprKind :: Lit ( _) => true ,
@@ -598,9 +598,9 @@ impl Token {
598598 /// otherwise returns the original token.
599599 pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
600600 match & self . kind {
601- Interpolated ( nt) => match * * nt {
601+ Interpolated ( nt) => match & nt . 0 {
602602 NtIdent ( ident, is_raw) => {
603- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
603+ Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
604604 }
605605 NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
606606 _ => Cow :: Borrowed ( self ) ,
@@ -615,8 +615,8 @@ impl Token {
615615 // We avoid using `Token::uninterpolate` here because it's slow.
616616 match & self . kind {
617617 & Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
618- Interpolated ( nt) => match * * nt {
619- NtIdent ( ident, is_raw) => Some ( ( ident, is_raw) ) ,
618+ Interpolated ( nt) => match & nt . 0 {
619+ NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
620620 _ => None ,
621621 } ,
622622 _ => None ,
@@ -629,8 +629,8 @@ impl Token {
629629 // We avoid using `Token::uninterpolate` here because it's slow.
630630 match & self . kind {
631631 & Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
632- Interpolated ( nt) => match * * nt {
633- NtLifetime ( ident) => Some ( ident) ,
632+ Interpolated ( nt) => match & nt . 0 {
633+ NtLifetime ( ident) => Some ( * ident) ,
634634 _ => None ,
635635 } ,
636636 _ => None ,
@@ -656,7 +656,7 @@ impl Token {
656656 /// Returns `true` if the token is an interpolated path.
657657 fn is_path ( & self ) -> bool {
658658 if let Interpolated ( nt) = & self . kind
659- && let NtPath ( ..) = * * nt
659+ && let NtPath ( ..) = & nt . 0
660660 {
661661 return true ;
662662 }
@@ -669,7 +669,7 @@ impl Token {
669669 /// (which happens while parsing the result of macro expansion)?
670670 pub fn is_whole_expr ( & self ) -> bool {
671671 if let Interpolated ( nt) = & self . kind
672- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
672+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
673673 {
674674 return true ;
675675 }
@@ -680,7 +680,7 @@ impl Token {
680680 /// Is the token an interpolated block (`$b:block`)?
681681 pub fn is_whole_block ( & self ) -> bool {
682682 if let Interpolated ( nt) = & self . kind
683- && let NtBlock ( ..) = * * nt
683+ && let NtBlock ( ..) = & nt . 0
684684 {
685685 return true ;
686686 }
@@ -928,7 +928,7 @@ impl fmt::Display for NonterminalKind {
928928}
929929
930930impl Nonterminal {
931- pub fn span ( & self ) -> Span {
931+ pub fn use_span ( & self ) -> Span {
932932 match self {
933933 NtItem ( item) => item. span ,
934934 NtBlock ( block) => block. span ,
@@ -942,6 +942,23 @@ impl Nonterminal {
942942 NtVis ( vis) => vis. span ,
943943 }
944944 }
945+
946+ pub fn descr ( & self ) -> & ' static str {
947+ match self {
948+ NtItem ( ..) => "item" ,
949+ NtBlock ( ..) => "block" ,
950+ NtStmt ( ..) => "statement" ,
951+ NtPat ( ..) => "pattern" ,
952+ NtExpr ( ..) => "expression" ,
953+ NtLiteral ( ..) => "literal" ,
954+ NtTy ( ..) => "type" ,
955+ NtIdent ( ..) => "identifier" ,
956+ NtLifetime ( ..) => "lifetime" ,
957+ NtMeta ( ..) => "attribute" ,
958+ NtPath ( ..) => "path" ,
959+ NtVis ( ..) => "visibility" ,
960+ }
961+ }
945962}
946963
947964impl PartialEq for Nonterminal {
0 commit comments