@@ -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)
@@ -388,7 +388,8 @@ impl TokenKind {
388388 match * self {
389389 Comma => Some ( vec ! [ Dot , Lt , Semi ] ) ,
390390 Semi => Some ( vec ! [ Colon , Comma ] ) ,
391- FatArrow => Some ( vec ! [ Eq , RArrow ] ) ,
391+ Colon => Some ( vec ! [ Semi ] ) ,
392+ FatArrow => Some ( vec ! [ Eq , RArrow , Ge , Gt ] ) ,
392393 _ => None ,
393394 }
394395 }
@@ -421,7 +422,7 @@ impl Token {
421422 /// if they keep spans or perform edition checks.
422423 pub fn uninterpolated_span ( & self ) -> Span {
423424 match & self . kind {
424- Interpolated ( nt) => nt. span ( ) ,
425+ Interpolated ( nt) => nt. 0 . use_span ( ) ,
425426 _ => self . span ,
426427 }
427428 }
@@ -464,7 +465,7 @@ impl Token {
464465 ModSep | // global path
465466 Lifetime ( ..) | // labeled loop
466467 Pound => true , // expression attributes
467- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
468+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
468469 NtExpr ( ..) |
469470 NtBlock ( ..) |
470471 NtPath ( ..) ) ,
@@ -488,7 +489,7 @@ impl Token {
488489 | DotDot | DotDotDot | DotDotEq // ranges
489490 | Lt | BinOp ( Shl ) // associated path
490491 | ModSep => true , // global path
491- Interpolated ( ref nt) => matches ! ( * * nt , NtLiteral ( ..) |
492+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtLiteral ( ..) |
492493 NtPat ( ..) |
493494 NtBlock ( ..) |
494495 NtPath ( ..) ) ,
@@ -511,7 +512,7 @@ impl Token {
511512 Lifetime ( ..) | // lifetime bound in trait object
512513 Lt | BinOp ( Shl ) | // associated path
513514 ModSep => true , // global path
514- Interpolated ( ref nt) => matches ! ( * * nt , NtTy ( ..) | NtPath ( ..) ) ,
515+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtTy ( ..) | NtPath ( ..) ) ,
515516 // For anonymous structs or unions, which only appear in specific positions
516517 // (type of struct fields or union fields), we don't consider them as regular types
517518 _ => false ,
@@ -522,7 +523,7 @@ impl Token {
522523 pub fn can_begin_const_arg ( & self ) -> bool {
523524 match self . kind {
524525 OpenDelim ( Delimiter :: Brace ) => true ,
525- Interpolated ( ref nt) => matches ! ( * * nt , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
526+ Interpolated ( ref nt) => matches ! ( & nt . 0 , NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
526527 _ => self . can_begin_literal_maybe_minus ( ) ,
527528 }
528529 }
@@ -576,7 +577,7 @@ impl Token {
576577 match self . uninterpolate ( ) . kind {
577578 Literal ( ..) | BinOp ( Minus ) => true ,
578579 Ident ( name, false ) if name. is_bool_lit ( ) => true ,
579- Interpolated ( ref nt) => match & * * nt {
580+ Interpolated ( ref nt) => match & nt . 0 {
580581 NtLiteral ( _) => true ,
581582 NtExpr ( e) => match & e. kind {
582583 ast:: ExprKind :: Lit ( _) => true ,
@@ -597,9 +598,9 @@ impl Token {
597598 /// otherwise returns the original token.
598599 pub fn uninterpolate ( & self ) -> Cow < ' _ , Token > {
599600 match & self . kind {
600- Interpolated ( nt) => match * * nt {
601+ Interpolated ( nt) => match & nt . 0 {
601602 NtIdent ( ident, is_raw) => {
602- Cow :: Owned ( Token :: new ( Ident ( ident. name , is_raw) , ident. span ) )
603+ Cow :: Owned ( Token :: new ( Ident ( ident. name , * is_raw) , ident. span ) )
603604 }
604605 NtLifetime ( ident) => Cow :: Owned ( Token :: new ( Lifetime ( ident. name ) , ident. span ) ) ,
605606 _ => Cow :: Borrowed ( self ) ,
@@ -614,8 +615,8 @@ impl Token {
614615 // We avoid using `Token::uninterpolate` here because it's slow.
615616 match & self . kind {
616617 & 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) ) ,
618+ Interpolated ( nt) => match & nt . 0 {
619+ NtIdent ( ident, is_raw) => Some ( ( * ident, * is_raw) ) ,
619620 _ => None ,
620621 } ,
621622 _ => None ,
@@ -628,8 +629,8 @@ impl Token {
628629 // We avoid using `Token::uninterpolate` here because it's slow.
629630 match & self . kind {
630631 & Lifetime ( name) => Some ( Ident :: new ( name, self . span ) ) ,
631- Interpolated ( nt) => match * * nt {
632- NtLifetime ( ident) => Some ( ident) ,
632+ Interpolated ( nt) => match & nt . 0 {
633+ NtLifetime ( ident) => Some ( * ident) ,
633634 _ => None ,
634635 } ,
635636 _ => None ,
@@ -655,7 +656,7 @@ impl Token {
655656 /// Returns `true` if the token is an interpolated path.
656657 fn is_path ( & self ) -> bool {
657658 if let Interpolated ( nt) = & self . kind
658- && let NtPath ( ..) = * * nt
659+ && let NtPath ( ..) = & nt . 0
659660 {
660661 return true ;
661662 }
@@ -668,7 +669,7 @@ impl Token {
668669 /// (which happens while parsing the result of macro expansion)?
669670 pub fn is_whole_expr ( & self ) -> bool {
670671 if let Interpolated ( nt) = & self . kind
671- && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = * * nt
672+ && let NtExpr ( _) | NtLiteral ( _) | NtPath ( _) | NtBlock ( _) = & nt . 0
672673 {
673674 return true ;
674675 }
@@ -679,7 +680,7 @@ impl Token {
679680 /// Is the token an interpolated block (`$b:block`)?
680681 pub fn is_whole_block ( & self ) -> bool {
681682 if let Interpolated ( nt) = & self . kind
682- && let NtBlock ( ..) = * * nt
683+ && let NtBlock ( ..) = & nt . 0
683684 {
684685 return true ;
685686 }
@@ -927,7 +928,7 @@ impl fmt::Display for NonterminalKind {
927928}
928929
929930impl Nonterminal {
930- pub fn span ( & self ) -> Span {
931+ pub fn use_span ( & self ) -> Span {
931932 match self {
932933 NtItem ( item) => item. span ,
933934 NtBlock ( block) => block. span ,
@@ -941,6 +942,23 @@ impl Nonterminal {
941942 NtVis ( vis) => vis. span ,
942943 }
943944 }
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+ }
944962}
945963
946964impl PartialEq for Nonterminal {
0 commit comments