@@ -210,16 +210,17 @@ impl Lit {
210210 }
211211 }
212212
213- /// Keep this in sync with `Token::can_begin_literal_maybe_minus` excluding unary negation.
213+ /// Keep this in sync with `Token::can_begin_literal_maybe_minus` and
214+ /// `Parser::eat_token_lit` (excluding unary negation).
214215 pub fn from_token ( token : & Token ) -> Option < Lit > {
215216 match token. uninterpolate ( ) . kind {
216217 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
217218 Literal ( token_lit) => Some ( token_lit) ,
218- Interpolated ( ref nt )
219- if let NtExpr ( expr ) | NtLiteral ( expr ) = & * * nt
220- && let ast :: ExprKind :: Lit ( token_lit ) = expr . kind =>
221- {
222- Some ( token_lit )
219+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
220+ MetaVarKind :: Literal | MetaVarKind :: Expr { .. } ,
221+ ) ) ) => {
222+ // Unreachable with the current test suite.
223+ panic ! ( "from_token metavar" ) ;
223224 }
224225 _ => None ,
225226 }
@@ -564,6 +565,9 @@ impl Token {
564565 /// for which spans affect name resolution and edition checks.
565566 /// Note that keywords are also identifiers, so they should use this
566567 /// if they keep spans or perform edition checks.
568+ //
569+ // Note: `Parser::uninterpolated_token_span` may give better information
570+ // than this method does.
567571 pub fn uninterpolated_span ( & self ) -> Span {
568572 match self . kind {
569573 NtIdent ( ident, _) | NtLifetime ( ident, _) => ident. span ,
@@ -616,12 +620,7 @@ impl Token {
616620 PathSep | // global path
617621 Lifetime ( ..) | // labeled loop
618622 Pound => true , // expression attributes
619- Interpolated ( ref nt) =>
620- matches ! ( & * * nt,
621- NtBlock ( ..) |
622- NtExpr ( ..) |
623- NtLiteral ( ..)
624- ) ,
623+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
625624 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
626625 MetaVarKind :: Block |
627626 MetaVarKind :: Expr { .. } |
@@ -652,11 +651,6 @@ impl Token {
652651 BinOp ( Shl ) => true , // path (double UFCS)
653652 // leading vert `|` or-pattern
654653 BinOp ( Or ) => matches ! ( pat_kind, PatWithOr ) ,
655- Interpolated ( nt) =>
656- matches ! ( & * * nt,
657- | NtExpr ( ..)
658- | NtLiteral ( ..)
659- ) ,
660654 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
661655 MetaVarKind :: Expr { .. } |
662656 MetaVarKind :: Literal |
@@ -699,7 +693,7 @@ impl Token {
699693 match self . kind {
700694 OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
701695 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
702- Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( .. ) | NtBlock ( .. ) | NtLiteral ( ..) ) ,
696+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
703697 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
704698 MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
705699 ) ) ) => true ,
@@ -743,22 +737,12 @@ impl Token {
743737 ///
744738 /// In other words, would this token be a valid start of `parse_literal_maybe_minus`?
745739 ///
746- /// Keep this in sync with and `Lit::from_token`, excluding unary negation.
740+ /// Keep this in sync with `Lit::from_token` and `Parser::eat_token_lit`
741+ /// (excluding unary negation).
747742 pub fn can_begin_literal_maybe_minus ( & self ) -> bool {
748743 match self . uninterpolate ( ) . kind {
749744 Literal ( ..) | BinOp ( Minus ) => true ,
750745 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
751- Interpolated ( ref nt) => match & * * nt {
752- NtLiteral ( _) => true ,
753- NtExpr ( e) => match & e. kind {
754- ast:: ExprKind :: Lit ( _) => true ,
755- ast:: ExprKind :: Unary ( ast:: UnOp :: Neg , e) => {
756- matches ! ( & e. kind, ast:: ExprKind :: Lit ( _) )
757- }
758- _ => false ,
759- } ,
760- _ => false ,
761- } ,
762746 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
763747 MetaVarKind :: Literal => true ,
764748 MetaVarKind :: Expr { can_begin_literal_maybe_minus, .. } => {
@@ -773,14 +757,6 @@ impl Token {
773757 pub fn can_begin_string_literal ( & self ) -> bool {
774758 match self . uninterpolate ( ) . kind {
775759 Literal ( ..) => true ,
776- Interpolated ( ref nt) => match & * * nt {
777- NtLiteral ( _) => true ,
778- NtExpr ( e) => match & e. kind {
779- ast:: ExprKind :: Lit ( _) => true ,
780- _ => false ,
781- } ,
782- _ => false ,
783- } ,
784760 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
785761 MetaVarKind :: Literal => true ,
786762 MetaVarKind :: Expr { can_begin_string_literal, .. } => can_begin_string_literal,
@@ -844,13 +820,16 @@ impl Token {
844820
845821 /// Is this a pre-parsed expression dropped into the token stream
846822 /// (which happens while parsing the result of macro expansion)?
847- pub fn is_whole_expr ( & self ) -> bool {
823+ pub fn is_metavar_expr ( & self ) -> bool {
848824 #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
849825 if let Interpolated ( nt) = & self . kind
850- && let NtExpr ( _ ) | NtLiteral ( _ ) | NtBlock ( _) = & * * nt
826+ && let NtBlock ( _) = & * * nt
851827 {
852828 true
853- } else if matches ! ( self . is_metavar_seq( ) , Some ( MetaVarKind :: Path ) ) {
829+ } else if matches ! (
830+ self . is_metavar_seq( ) ,
831+ Some ( MetaVarKind :: Expr { .. } | MetaVarKind :: Literal | MetaVarKind :: Path )
832+ ) {
854833 true
855834 } else {
856835 false
@@ -859,6 +838,7 @@ impl Token {
859838
860839 /// Is the token an interpolated block (`$b:block`)?
861840 pub fn is_whole_block ( & self ) -> bool {
841+ #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
862842 if let Interpolated ( nt) = & self . kind
863843 && let NtBlock ( ..) = & * * nt
864844 {
@@ -1052,8 +1032,6 @@ pub enum NtExprKind {
10521032/// For interpolation during macro expansion.
10531033pub enum Nonterminal {
10541034 NtBlock ( P < ast:: Block > ) ,
1055- NtExpr ( P < ast:: Expr > ) ,
1056- NtLiteral ( P < ast:: Expr > ) ,
10571035}
10581036
10591037#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
@@ -1143,15 +1121,12 @@ impl Nonterminal {
11431121 pub fn use_span ( & self ) -> Span {
11441122 match self {
11451123 NtBlock ( block) => block. span ,
1146- NtExpr ( expr) | NtLiteral ( expr) => expr. span ,
11471124 }
11481125 }
11491126
11501127 pub fn descr ( & self ) -> & ' static str {
11511128 match self {
11521129 NtBlock ( ..) => "block" ,
1153- NtExpr ( ..) => "expression" ,
1154- NtLiteral ( ..) => "literal" ,
11551130 }
11561131 }
11571132}
@@ -1170,8 +1145,6 @@ impl fmt::Debug for Nonterminal {
11701145 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
11711146 match * self {
11721147 NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1173- NtExpr ( ..) => f. pad ( "NtExpr(..)" ) ,
1174- NtLiteral ( ..) => f. pad ( "NtLiteral(..)" ) ,
11751148 }
11761149 }
11771150}
@@ -1194,7 +1167,7 @@ mod size_asserts {
11941167 // tidy-alphabetical-start
11951168 static_assert_size ! ( Lit , 12 ) ;
11961169 static_assert_size ! ( LitKind , 2 ) ;
1197- static_assert_size ! ( Nonterminal , 16 ) ;
1170+ static_assert_size ! ( Nonterminal , 8 ) ;
11981171 static_assert_size ! ( Token , 24 ) ;
11991172 static_assert_size ! ( TokenKind , 16 ) ;
12001173 // tidy-alphabetical-end
0 commit comments