@@ -211,16 +211,17 @@ impl Lit {
211211 }
212212 }
213213
214- /// Keep this in sync with `Token::can_begin_literal_maybe_minus` excluding unary negation.
214+ /// Keep this in sync with `Token::can_begin_literal_maybe_minus` and
215+ /// `Parser::eat_token_lit` (excluding unary negation).
215216 pub fn from_token ( token : & Token ) -> Option < Lit > {
216217 match token. uninterpolate ( ) . kind {
217218 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
218219 Literal ( token_lit) => Some ( token_lit) ,
219- Interpolated ( ref nt )
220- if let NtExpr ( expr ) | NtLiteral ( expr ) = & * * nt
221- && let ast :: ExprKind :: Lit ( token_lit ) = expr . kind =>
222- {
223- Some ( token_lit )
220+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
221+ MetaVarKind :: Literal | MetaVarKind :: Expr { .. } ,
222+ ) ) ) => {
223+ // Unreachable with the current test suite.
224+ panic ! ( "from_token metavar" ) ;
224225 }
225226 _ => None ,
226227 }
@@ -565,6 +566,9 @@ impl Token {
565566 /// for which spans affect name resolution and edition checks.
566567 /// Note that keywords are also identifiers, so they should use this
567568 /// if they keep spans or perform edition checks.
569+ //
570+ // Note: `Parser::uninterpolated_token_span` may give better information
571+ // than this method does.
568572 pub fn uninterpolated_span ( & self ) -> Span {
569573 match self . kind {
570574 NtIdent ( ident, _) | NtLifetime ( ident, _) => ident. span ,
@@ -617,12 +621,7 @@ impl Token {
617621 PathSep | // global path
618622 Lifetime ( ..) | // labeled loop
619623 Pound => true , // expression attributes
620- Interpolated ( ref nt) =>
621- matches ! ( & * * nt,
622- NtBlock ( ..) |
623- NtExpr ( ..) |
624- NtLiteral ( ..)
625- ) ,
624+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
626625 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
627626 MetaVarKind :: Block |
628627 MetaVarKind :: Expr { .. } |
@@ -653,11 +652,6 @@ impl Token {
653652 BinOp ( Shl ) => true , // path (double UFCS)
654653 // leading vert `|` or-pattern
655654 BinOp ( Or ) => matches ! ( pat_kind, PatWithOr ) ,
656- Interpolated ( nt) =>
657- matches ! ( & * * nt,
658- | NtExpr ( ..)
659- | NtLiteral ( ..)
660- ) ,
661655 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
662656 MetaVarKind :: Expr { .. } |
663657 MetaVarKind :: Literal |
@@ -700,7 +694,7 @@ impl Token {
700694 match self . kind {
701695 OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
702696 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
703- Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( .. ) | NtBlock ( .. ) | NtLiteral ( ..) ) ,
697+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
704698 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
705699 MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
706700 ) ) ) => true ,
@@ -744,22 +738,12 @@ impl Token {
744738 ///
745739 /// In other words, would this token be a valid start of `parse_literal_maybe_minus`?
746740 ///
747- /// Keep this in sync with and `Lit::from_token`, excluding unary negation.
741+ /// Keep this in sync with `Lit::from_token` and `Parser::eat_token_lit`
742+ /// (excluding unary negation).
748743 pub fn can_begin_literal_maybe_minus ( & self ) -> bool {
749744 match self . uninterpolate ( ) . kind {
750745 Literal ( ..) | BinOp ( Minus ) => true ,
751746 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
752- Interpolated ( ref nt) => match & * * nt {
753- NtLiteral ( _) => true ,
754- NtExpr ( e) => match & e. kind {
755- ast:: ExprKind :: Lit ( _) => true ,
756- ast:: ExprKind :: Unary ( ast:: UnOp :: Neg , e) => {
757- matches ! ( & e. kind, ast:: ExprKind :: Lit ( _) )
758- }
759- _ => false ,
760- } ,
761- _ => false ,
762- } ,
763747 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
764748 MetaVarKind :: Literal => true ,
765749 MetaVarKind :: Expr { can_begin_literal_maybe_minus, .. } => {
@@ -774,14 +758,6 @@ impl Token {
774758 pub fn can_begin_string_literal ( & self ) -> bool {
775759 match self . uninterpolate ( ) . kind {
776760 Literal ( ..) => true ,
777- Interpolated ( ref nt) => match & * * nt {
778- NtLiteral ( _) => true ,
779- NtExpr ( e) => match & e. kind {
780- ast:: ExprKind :: Lit ( _) => true ,
781- _ => false ,
782- } ,
783- _ => false ,
784- } ,
785761 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
786762 MetaVarKind :: Literal => true ,
787763 MetaVarKind :: Expr { can_begin_string_literal, .. } => can_begin_string_literal,
@@ -845,13 +821,16 @@ impl Token {
845821
846822 /// Is this a pre-parsed expression dropped into the token stream
847823 /// (which happens while parsing the result of macro expansion)?
848- pub fn is_whole_expr ( & self ) -> bool {
824+ pub fn is_metavar_expr ( & self ) -> bool {
849825 #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
850826 if let Interpolated ( nt) = & self . kind
851- && let NtExpr ( _ ) | NtLiteral ( _ ) | NtBlock ( _) = & * * nt
827+ && let NtBlock ( _) = & * * nt
852828 {
853829 true
854- } else if matches ! ( self . is_metavar_seq( ) , Some ( MetaVarKind :: Path ) ) {
830+ } else if matches ! (
831+ self . is_metavar_seq( ) ,
832+ Some ( MetaVarKind :: Expr { .. } | MetaVarKind :: Literal | MetaVarKind :: Path )
833+ ) {
855834 true
856835 } else {
857836 false
@@ -860,6 +839,7 @@ impl Token {
860839
861840 /// Is the token an interpolated block (`$b:block`)?
862841 pub fn is_whole_block ( & self ) -> bool {
842+ #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
863843 if let Interpolated ( nt) = & self . kind
864844 && let NtBlock ( ..) = & * * nt
865845 {
@@ -1060,8 +1040,6 @@ pub enum NtExprKind {
10601040/// For interpolation during macro expansion.
10611041pub enum Nonterminal {
10621042 NtBlock ( P < ast:: Block > ) ,
1063- NtExpr ( P < ast:: Expr > ) ,
1064- NtLiteral ( P < ast:: Expr > ) ,
10651043}
10661044
10671045#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
@@ -1151,15 +1129,12 @@ impl Nonterminal {
11511129 pub fn use_span ( & self ) -> Span {
11521130 match self {
11531131 NtBlock ( block) => block. span ,
1154- NtExpr ( expr) | NtLiteral ( expr) => expr. span ,
11551132 }
11561133 }
11571134
11581135 pub fn descr ( & self ) -> & ' static str {
11591136 match self {
11601137 NtBlock ( ..) => "block" ,
1161- NtExpr ( ..) => "expression" ,
1162- NtLiteral ( ..) => "literal" ,
11631138 }
11641139 }
11651140}
@@ -1178,8 +1153,6 @@ impl fmt::Debug for Nonterminal {
11781153 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
11791154 match * self {
11801155 NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1181- NtExpr ( ..) => f. pad ( "NtExpr(..)" ) ,
1182- NtLiteral ( ..) => f. pad ( "NtLiteral(..)" ) ,
11831156 }
11841157 }
11851158}
@@ -1202,7 +1175,7 @@ mod size_asserts {
12021175 // tidy-alphabetical-start
12031176 static_assert_size ! ( Lit , 12 ) ;
12041177 static_assert_size ! ( LitKind , 2 ) ;
1205- static_assert_size ! ( Nonterminal , 16 ) ;
1178+ static_assert_size ! ( Nonterminal , 8 ) ;
12061179 static_assert_size ! ( Token , 24 ) ;
12071180 static_assert_size ! ( TokenKind , 16 ) ;
12081181 // tidy-alphabetical-end
0 commit comments