@@ -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 ,
@@ -655,7 +655,7 @@ impl Token {
655655 /// Returns `true` if the token is an interpolated path.
656656 fn is_path ( & self ) -> bool {
657657 if let Interpolated ( nt) = & self . kind
658- && let NtPath ( ..) = * * nt
658+ && let NtPath ( ..) = & nt . 0
659659 {
660660 return true ;
661661 }
@@ -668,7 +668,7 @@ impl Token {
668668 /// (which happens while parsing the result of macro expansion)?
669669 pub fn is_whole_expr ( & self ) -> bool {
670670 if let Interpolated ( nt) = & self . kind
671- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
671+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
672672 {
673673 return true ;
674674 }
@@ -679,7 +679,7 @@ impl Token {
679679 /// Is the token an interpolated block (`$b:block`)?
680680 pub fn is_whole_block ( & self ) -> bool {
681681 if let Interpolated ( nt) = & self . kind
682- && let NtBlock ( ..) = * * nt
682+ && let NtBlock ( ..) = & nt . 0
683683 {
684684 return true ;
685685 }
@@ -927,7 +927,7 @@ impl fmt::Display for NonterminalKind {
927927}
928928
929929impl Nonterminal {
930- pub fn span ( & self ) -> Span {
930+ pub fn use_span ( & self ) -> Span {
931931 match self {
932932 NtItem ( item) => item. span ,
933933 NtBlock ( block) => block. span ,
@@ -941,6 +941,23 @@ impl Nonterminal {
941941 NtVis ( vis) => vis. span ,
942942 }
943943 }
944+
945+ pub fn descr ( & self ) -> & ' static str {
946+ match self {
947+ NtItem ( ..) => "item" ,
948+ NtBlock ( ..) => "block" ,
949+ NtStmt ( ..) => "statement" ,
950+ NtPat ( ..) => "pattern" ,
951+ NtExpr ( ..) => "expression" ,
952+ NtLiteral ( ..) => "literal" ,
953+ NtTy ( ..) => "type" ,
954+ NtIdent ( ..) => "identifier" ,
955+ NtLifetime ( ..) => "lifetime" ,
956+ NtMeta ( ..) => "attribute" ,
957+ NtPath ( ..) => "path" ,
958+ NtVis ( ..) => "visibility" ,
959+ }
960+ }
944961}
945962
946963impl PartialEq for Nonterminal {
0 commit comments