@@ -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 }
@@ -558,6 +559,9 @@ impl Token {
558559 /// for which spans affect name resolution and edition checks.
559560 /// Note that keywords are also identifiers, so they should use this
560561 /// if they keep spans or perform edition checks.
562+ //
563+ // Note: `Parser::uninterpolated_token_span` may give better information
564+ // than this method does.
561565 pub fn uninterpolated_span ( & self ) -> Span {
562566 match self . kind {
563567 NtIdent ( ident, _) | NtLifetime ( ident, _) => ident. span ,
@@ -610,12 +614,7 @@ impl Token {
610614 PathSep | // global path
611615 Lifetime ( ..) | // labeled loop
612616 Pound => true , // expression attributes
613- Interpolated ( ref nt) =>
614- matches ! ( & * * nt,
615- NtBlock ( ..) |
616- NtExpr ( ..) |
617- NtLiteral ( ..)
618- ) ,
617+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
619618 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
620619 MetaVarKind :: Block |
621620 MetaVarKind :: Expr { .. } |
@@ -646,11 +645,6 @@ impl Token {
646645 BinOp ( Shl ) => true , // path (double UFCS)
647646 // leading vert `|` or-pattern
648647 BinOp ( Or ) => matches ! ( pat_kind, PatWithOr ) ,
649- Interpolated ( nt) =>
650- matches ! ( & * * nt,
651- | NtExpr ( ..)
652- | NtLiteral ( ..)
653- ) ,
654648 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
655649 MetaVarKind :: Expr { .. } |
656650 MetaVarKind :: Literal |
@@ -693,7 +687,7 @@ impl Token {
693687 match self . kind {
694688 OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
695689 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
696- Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( .. ) | NtBlock ( .. ) | NtLiteral ( ..) ) ,
690+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
697691 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
698692 MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
699693 ) ) ) => true ,
@@ -737,22 +731,12 @@ impl Token {
737731 ///
738732 /// In other words, would this token be a valid start of `parse_literal_maybe_minus`?
739733 ///
740- /// Keep this in sync with and `Lit::from_token`, excluding unary negation.
734+ /// Keep this in sync with `Lit::from_token` and `Parser::eat_token_lit`
735+ /// (excluding unary negation).
741736 pub fn can_begin_literal_maybe_minus ( & self ) -> bool {
742737 match self . uninterpolate ( ) . kind {
743738 Literal ( ..) | BinOp ( Minus ) => true ,
744739 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
745- Interpolated ( ref nt) => match & * * nt {
746- NtLiteral ( _) => true ,
747- NtExpr ( e) => match & e. kind {
748- ast:: ExprKind :: Lit ( _) => true ,
749- ast:: ExprKind :: Unary ( ast:: UnOp :: Neg , e) => {
750- matches ! ( & e. kind, ast:: ExprKind :: Lit ( _) )
751- }
752- _ => false ,
753- } ,
754- _ => false ,
755- } ,
756740 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
757741 MetaVarKind :: Literal => true ,
758742 MetaVarKind :: Expr { can_begin_literal_maybe_minus, .. } => {
@@ -767,14 +751,6 @@ impl Token {
767751 pub fn can_begin_string_literal ( & self ) -> bool {
768752 match self . uninterpolate ( ) . kind {
769753 Literal ( ..) => true ,
770- Interpolated ( ref nt) => match & * * nt {
771- NtLiteral ( _) => true ,
772- NtExpr ( e) => match & e. kind {
773- ast:: ExprKind :: Lit ( _) => true ,
774- _ => false ,
775- } ,
776- _ => false ,
777- } ,
778754 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
779755 MetaVarKind :: Literal => true ,
780756 MetaVarKind :: Expr { can_begin_string_literal, .. } => can_begin_string_literal,
@@ -838,13 +814,16 @@ impl Token {
838814
839815 /// Is this a pre-parsed expression dropped into the token stream
840816 /// (which happens while parsing the result of macro expansion)?
841- pub fn is_whole_expr ( & self ) -> bool {
817+ pub fn is_metavar_expr ( & self ) -> bool {
842818 #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
843819 if let Interpolated ( nt) = & self . kind
844- && let NtExpr ( _ ) | NtLiteral ( _ ) | NtBlock ( _) = & * * nt
820+ && let NtBlock ( _) = & * * nt
845821 {
846822 true
847- } else if matches ! ( self . is_metavar_seq( ) , Some ( MetaVarKind :: Path ) ) {
823+ } else if matches ! (
824+ self . is_metavar_seq( ) ,
825+ Some ( MetaVarKind :: Expr { .. } | MetaVarKind :: Literal | MetaVarKind :: Path )
826+ ) {
848827 true
849828 } else {
850829 false
@@ -853,6 +832,7 @@ impl Token {
853832
854833 /// Is the token an interpolated block (`$b:block`)?
855834 pub fn is_whole_block ( & self ) -> bool {
835+ #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
856836 if let Interpolated ( nt) = & self . kind
857837 && let NtBlock ( ..) = & * * nt
858838 {
@@ -1046,8 +1026,6 @@ pub enum NtExprKind {
10461026/// For interpolation during macro expansion.
10471027pub enum Nonterminal {
10481028 NtBlock ( P < ast:: Block > ) ,
1049- NtExpr ( P < ast:: Expr > ) ,
1050- NtLiteral ( P < ast:: Expr > ) ,
10511029}
10521030
10531031#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
@@ -1137,15 +1115,12 @@ impl Nonterminal {
11371115 pub fn use_span ( & self ) -> Span {
11381116 match self {
11391117 NtBlock ( block) => block. span ,
1140- NtExpr ( expr) | NtLiteral ( expr) => expr. span ,
11411118 }
11421119 }
11431120
11441121 pub fn descr ( & self ) -> & ' static str {
11451122 match self {
11461123 NtBlock ( ..) => "block" ,
1147- NtExpr ( ..) => "expression" ,
1148- NtLiteral ( ..) => "literal" ,
11491124 }
11501125 }
11511126}
@@ -1164,8 +1139,6 @@ impl fmt::Debug for Nonterminal {
11641139 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
11651140 match * self {
11661141 NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1167- NtExpr ( ..) => f. pad ( "NtExpr(..)" ) ,
1168- NtLiteral ( ..) => f. pad ( "NtLiteral(..)" ) ,
11691142 }
11701143 }
11711144}
@@ -1188,7 +1161,7 @@ mod size_asserts {
11881161 // tidy-alphabetical-start
11891162 static_assert_size ! ( Lit , 12 ) ;
11901163 static_assert_size ! ( LitKind , 2 ) ;
1191- static_assert_size ! ( Nonterminal , 16 ) ;
1164+ static_assert_size ! ( Nonterminal , 8 ) ;
11921165 static_assert_size ! ( Token , 24 ) ;
11931166 static_assert_size ! ( TokenKind , 16 ) ;
11941167 // tidy-alphabetical-end
0 commit comments