@@ -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)
@@ -421,7 +421,7 @@ impl Token {
421421 /// if they keep spans or perform edition checks.
422422 pub fn uninterpolated_span ( & self ) -> Span {
423423 match & self . kind {
424- Interpolated ( nt) => nt. span ( ) ,
424+ Interpolated ( nt) => nt. 0 . use_span ( ) ,
425425 _ => self . span ,
426426 }
427427 }
@@ -464,7 +464,7 @@ impl Token {
464464 ModSep | // global path
465465 Lifetime ( ..) | // labeled loop
466466 Pound => true , // expression attributes
467- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
467+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
468468 NtExpr ( ..) |
469469 NtBlock ( ..) |
470470 NtPath ( ..) ) ,
@@ -488,7 +488,7 @@ impl Token {
488488 | DotDot | DotDotDot | DotDotEq // ranges
489489 | Lt | BinOp ( Shl ) // associated path
490490 | ModSep => true , // global path
491- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
491+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
492492 NtPat ( ..) |
493493 NtBlock ( ..) |
494494 NtPath ( ..) ) ,
@@ -511,7 +511,7 @@ impl Token {
511511 Lifetime ( ..) | // lifetime bound in trait object
512512 Lt | BinOp ( Shl ) | // associated path
513513 ModSep => true , // global path
514- Interpolated ( ref nt) => matches ! ( * * nt , NtTy ( ..) | NtPath ( ..) ) ,
514+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
515515 // For anonymous structs or unions, which only appear in specific positions
516516 // (type of struct fields or union fields), we don't consider them as regular types
517517 _ => false ,
@@ -522,7 +522,7 @@ impl Token {
522522 pub fn can_begin_const_arg ( & self ) -> bool {
523523 match self . kind {
524524 OpenDelim ( Delimiter :: Brace ) => true ,
525- Interpolated ( ref nt) => matches ! ( * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
525+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
526526 _ => self . can_begin_literal_maybe_minus ( ) ,
527527 }
528528 }
@@ -576,7 +576,7 @@ impl Token {
576576 match self . uninterpolate ( ) . kind {
577577 Literal ( ..) | BinOp ( Minus ) => true ,
578578 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
579- Interpolated ( ref nt) => match & * * nt {
579+ Interpolated ( ref nt) => match & nt . 0 {
580580 NtLiteral ( _) => true ,
581581 NtExpr ( e) => match & e. kind {
582582 ast:: ExprKind :: Lit ( _) => true ,
@@ -597,9 +597,9 @@ impl Token {
597597 /// otherwise returns the original token.
598598 pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
599599 match & self . kind {
600- Interpolated ( nt) => match * * nt {
600+ Interpolated ( nt) => match & nt . 0 {
601601 NtIdent ( ident, is_raw) => {
602- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
602+ Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
603603 }
604604 NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
605605 _ => Cow :: Borrowed ( self ) ,
@@ -614,8 +614,8 @@ impl Token {
614614 // We avoid using `Token::uninterpolate` here because it's slow.
615615 match & self . kind {
616616 & Ident ( name, is_raw) => Some ( ( Ident :: new ( name, self . span ) , is_raw) ) ,
617- Interpolated ( nt) => match * * nt {
618- NtIdent ( ident, is_raw) => Some ( ( ident, is_raw) ) ,
617+ Interpolated ( nt) => match & nt . 0 {
618+ NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
619619 _ => None ,
620620 } ,
621621 _ => None ,
@@ -628,8 +628,8 @@ impl Token {
628628 // We avoid using `Token::uninterpolate` here because it's slow.
629629 match & self . kind {
630630 & Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
631- Interpolated ( nt) => match * * nt {
632- NtLifetime ( ident) => Some ( ident) ,
631+ Interpolated ( nt) => match & nt . 0 {
632+ NtLifetime ( ident) => Some ( * ident) ,
633633 _ => None ,
634634 } ,
635635 _ => None ,
@@ -654,9 +654,7 @@ impl Token {
654654
655655 /// Returns `true` if the token is an interpolated path.
656656 fn is_path ( & self ) -> bool {
657- if let Interpolated ( nt) = & self . kind
658- && let NtPath ( ..) = * * nt
659- {
657+ if let Interpolated ( nt) = & self . kind && let NtPath ( ..) = & nt. 0 {
660658 return true ;
661659 }
662660
@@ -668,7 +666,7 @@ impl Token {
668666 /// (which happens while parsing the result of macro expansion)?
669667 pub fn is_whole_expr ( & self ) -> bool {
670668 if let Interpolated ( nt) = & self . kind
671- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
669+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
672670 {
673671 return true ;
674672 }
@@ -678,9 +676,7 @@ impl Token {
678676
679677 /// Is the token an interpolated block (`$b:block`)?
680678 pub fn is_whole_block ( & self ) -> bool {
681- if let Interpolated ( nt) = & self . kind
682- && let NtBlock ( ..) = * * nt
683- {
679+ if let Interpolated ( nt) = & self . kind && let NtBlock ( ..) = & nt. 0 {
684680 return true ;
685681 }
686682
@@ -927,7 +923,7 @@ impl fmt::Display for NonterminalKind {
927923}
928924
929925impl Nonterminal {
930- pub fn span ( & self ) -> Span {
926+ pub fn use_span ( & self ) -> Span {
931927 match self {
932928 NtItem ( item) => item. span ,
933929 NtBlock ( block) => block. span ,
@@ -941,6 +937,23 @@ impl Nonterminal {
941937 NtVis ( vis) => vis. span ,
942938 }
943939 }
940+
941+ pub fn descr ( & self ) -> & ' static str {
942+ match self {
943+ NtItem ( ..) => "item" ,
944+ NtBlock ( ..) => "block" ,
945+ NtStmt ( ..) => "statement" ,
946+ NtPat ( ..) => "pattern" ,
947+ NtExpr ( ..) => "expression" ,
948+ NtLiteral ( ..) => "literal" ,
949+ NtTy ( ..) => "type" ,
950+ NtIdent ( ..) => "identifier" ,
951+ NtLifetime ( ..) => "lifetime" ,
952+ NtMeta ( ..) => "attribute" ,
953+ NtPath ( ..) => "path" ,
954+ NtVis ( ..) => "visibility" ,
955+ }
956+ }
944957}
945958
946959impl PartialEq for Nonterminal {
0 commit comments