@@ -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)
@@ -313,7 +313,7 @@ pub enum TokenKind {
313313 /// - It prevents `Token` from implementing `Copy`.
314314 /// It adds complexity and likely slows things down. Please don't add new
315315 /// occurrences of this token kind!
316- Interpolated ( Lrc < Nonterminal > ) ,
316+ Interpolated ( Lrc < ( Nonterminal , Span ) > ) ,
317317
318318 /// A doc comment token.
319319 /// `Symbol` is the doc comment's data excluding its "quotes" (`///`, `/**`, etc)
@@ -420,7 +420,7 @@ impl Token {
420420 /// if they keep spans or perform edition checks.
421421 pub fn uninterpolated_span ( & self ) -> Span {
422422 match & self . kind {
423- Interpolated ( nt) => nt. span ( ) ,
423+ Interpolated ( nt) => nt. 0 . use_span ( ) ,
424424 _ => self . span ,
425425 }
426426 }
@@ -463,7 +463,7 @@ impl Token {
463463 ModSep | // global path
464464 Lifetime ( ..) | // labeled loop
465465 Pound => true , // expression attributes
466- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
466+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
467467 NtExpr ( ..) |
468468 NtBlock ( ..) |
469469 NtPath ( ..) ) ,
@@ -487,7 +487,7 @@ impl Token {
487487 | DotDot | DotDotDot | DotDotEq // ranges
488488 | Lt | BinOp ( Shl ) // associated path
489489 | ModSep => true , // global path
490- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
490+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
491491 NtPat ( ..) |
492492 NtBlock ( ..) |
493493 NtPath ( ..) ) ,
@@ -510,7 +510,7 @@ impl Token {
510510 Lifetime ( ..) | // lifetime bound in trait object
511511 Lt | BinOp ( Shl ) | // associated path
512512 ModSep => true , // global path
513- Interpolated ( ref nt) => matches ! ( * * nt , NtTy ( ..) | NtPath ( ..) ) ,
513+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
514514 // For anonymous structs or unions, which only appear in specific positions
515515 // (type of struct fields or union fields), we don't consider them as regular types
516516 _ => false ,
@@ -521,7 +521,7 @@ impl Token {
521521 pub fn can_begin_const_arg ( & self ) -> bool {
522522 match self . kind {
523523 OpenDelim ( Delimiter :: Brace ) => true ,
524- Interpolated ( ref nt) => matches ! ( * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
524+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
525525 _ => self . can_begin_literal_maybe_minus ( ) ,
526526 }
527527 }
@@ -575,7 +575,7 @@ impl Token {
575575 match self . uninterpolate ( ) . kind {
576576 Literal ( ..) | BinOp ( Minus ) => true ,
577577 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
578- Interpolated ( ref nt) => match & * * nt {
578+ Interpolated ( ref nt) => match & nt . 0 {
579579 NtLiteral ( _) => true ,
580580 NtExpr ( e) => match & e. kind {
581581 ast:: ExprKind :: Lit ( _) => true ,
@@ -596,9 +596,9 @@ impl Token {
596596 /// otherwise returns the original token.
597597 pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
598598 match & self . kind {
599- Interpolated ( nt) => match * * nt {
599+ Interpolated ( nt) => match & nt . 0 {
600600 NtIdent ( ident, is_raw) => {
601- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
601+ Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
602602 }
603603 NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
604604 _ => Cow :: Borrowed ( self ) ,
@@ -613,8 +613,8 @@ impl Token {
613613 // We avoid using `Token::uninterpolate` here because it's slow.
614614 match & self . kind {
615615 & Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
616- Interpolated ( nt) => match * * nt {
617- NtIdent ( ident, is_raw) => Some ( ( ident, is_raw) ) ,
616+ Interpolated ( nt) => match & nt . 0 {
617+ NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
618618 _ => None ,
619619 } ,
620620 _ => None ,
@@ -627,8 +627,8 @@ impl Token {
627627 // We avoid using `Token::uninterpolate` here because it's slow.
628628 match & self . kind {
629629 & Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
630- Interpolated ( nt) => match * * nt {
631- NtLifetime ( ident) => Some ( ident) ,
630+ Interpolated ( nt) => match & nt . 0 {
631+ NtLifetime ( ident) => Some ( * ident) ,
632632 _ => None ,
633633 } ,
634634 _ => None ,
@@ -653,9 +653,7 @@ impl Token {
653653
654654 /// Returns `true` if the token is an interpolated path.
655655 fn is_path ( & self ) -> bool {
656- if let Interpolated ( nt) = & self . kind
657- && let NtPath ( ..) = * * nt
658- {
656+ if let Interpolated ( nt) = & self . kind && let NtPath ( ..) = & nt. 0 {
659657 return true ;
660658 }
661659
@@ -667,7 +665,7 @@ impl Token {
667665 /// (which happens while parsing the result of macro expansion)?
668666 pub fn is_whole_expr ( & self ) -> bool {
669667 if let Interpolated ( nt) = & self . kind
670- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
668+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
671669 {
672670 return true ;
673671 }
@@ -677,9 +675,7 @@ impl Token {
677675
678676 /// Is the token an interpolated block (`$b:block`)?
679677 pub fn is_whole_block ( & self ) -> bool {
680- if let Interpolated ( nt) = & self . kind
681- && let NtBlock ( ..) = * * nt
682- {
678+ if let Interpolated ( nt) = & self . kind && let NtBlock ( ..) = & nt. 0 {
683679 return true ;
684680 }
685681
@@ -926,7 +922,7 @@ impl fmt::Display for NonterminalKind {
926922}
927923
928924impl Nonterminal {
929- pub fn span ( & self ) -> Span {
925+ pub fn use_span ( & self ) -> Span {
930926 match self {
931927 NtItem ( item) => item. span ,
932928 NtBlock ( block) => block. span ,
@@ -940,6 +936,23 @@ impl Nonterminal {
940936 NtVis ( vis) => vis. span ,
941937 }
942938 }
939+
940+ pub fn descr ( & self ) -> & ' static str {
941+ match self {
942+ NtItem ( ..) => "item" ,
943+ NtBlock ( ..) => "block" ,
944+ NtStmt ( ..) => "statement" ,
945+ NtPat ( ..) => "pattern" ,
946+ NtExpr ( ..) => "expression" ,
947+ NtLiteral ( ..) => "literal" ,
948+ NtTy ( ..) => "type" ,
949+ NtIdent ( ..) => "identifier" ,
950+ NtLifetime ( ..) => "lifetime" ,
951+ NtMeta ( ..) => "attribute" ,
952+ NtPath ( ..) => "path" ,
953+ NtVis ( ..) => "visibility" ,
954+ }
955+ }
943956}
944957
945958impl PartialEq for Nonterminal {
0 commit comments