@@ -214,16 +214,17 @@ impl Lit {
214214 }
215215 }
216216
217- /// Keep this in sync with `Token::can_begin_literal_maybe_minus` excluding unary negation.
217+ /// Keep this in sync with `Token::can_begin_literal_maybe_minus` and
218+ /// `Parser::eat_token_lit` (excluding unary negation).
218219 pub fn from_token ( token : & Token ) -> Option < Lit > {
219220 match token. uninterpolate ( ) . kind {
220221 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => Some ( Lit :: new ( Bool , name, None ) ) ,
221222 Literal ( token_lit) => Some ( token_lit) ,
222- Interpolated ( ref nt )
223- if let NtExpr ( expr ) | NtLiteral ( expr ) = & * * nt
224- && let ast :: ExprKind :: Lit ( token_lit ) = expr . kind =>
225- {
226- Some ( token_lit )
223+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
224+ MetaVarKind :: Literal | MetaVarKind :: Expr { .. } ,
225+ ) ) ) => {
226+ // Unreachable with the current test suite.
227+ panic ! ( "from_token metavar" ) ;
227228 }
228229 _ => None ,
229230 }
@@ -568,6 +569,9 @@ impl Token {
568569 /// for which spans affect name resolution and edition checks.
569570 /// Note that keywords are also identifiers, so they should use this
570571 /// if they keep spans or perform edition checks.
572+ //
573+ // Note: `Parser::uninterpolated_token_span` may give better information
574+ // than this method does.
571575 pub fn uninterpolated_span ( & self ) -> Span {
572576 match self . kind {
573577 NtIdent ( ident, _) | NtLifetime ( ident, _) => ident. span ,
@@ -620,12 +624,7 @@ impl Token {
620624 PathSep | // global path
621625 Lifetime ( ..) | // labeled loop
622626 Pound => true , // expression attributes
623- Interpolated ( ref nt) =>
624- matches ! ( & * * nt,
625- NtBlock ( ..) |
626- NtExpr ( ..) |
627- NtLiteral ( ..)
628- ) ,
627+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
629628 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
630629 MetaVarKind :: Block |
631630 MetaVarKind :: Expr { .. } |
@@ -656,11 +655,6 @@ impl Token {
656655 BinOp ( Shl ) => true , // path (double UFCS)
657656 // leading vert `|` or-pattern
658657 BinOp ( Or ) => matches ! ( pat_kind, PatWithOr ) ,
659- Interpolated ( nt) =>
660- matches ! ( & * * nt,
661- | NtExpr ( ..)
662- | NtLiteral ( ..)
663- ) ,
664658 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
665659 MetaVarKind :: Expr { .. } |
666660 MetaVarKind :: Literal |
@@ -703,7 +697,7 @@ impl Token {
703697 match self . kind {
704698 OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
705699 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
706- Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( .. ) | NtBlock ( .. ) | NtLiteral ( ..) ) ,
700+ Interpolated ( ref nt) => matches ! ( & * * nt, NtBlock ( ..) ) ,
707701 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
708702 MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
709703 ) ) ) => true ,
@@ -747,22 +741,12 @@ impl Token {
747741 ///
748742 /// In other words, would this token be a valid start of `parse_literal_maybe_minus`?
749743 ///
750- /// Keep this in sync with and `Lit::from_token`, excluding unary negation.
744+ /// Keep this in sync with `Lit::from_token` and `Parser::eat_token_lit`
745+ /// (excluding unary negation).
751746 pub fn can_begin_literal_maybe_minus ( & self ) -> bool {
752747 match self . uninterpolate ( ) . kind {
753748 Literal ( ..) | BinOp ( Minus ) => true ,
754749 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
755- Interpolated ( ref nt) => match & * * nt {
756- NtLiteral ( _) => true ,
757- NtExpr ( e) => match & e. kind {
758- ast:: ExprKind :: Lit ( _) => true ,
759- ast:: ExprKind :: Unary ( ast:: UnOp :: Neg , e) => {
760- matches ! ( & e. kind, ast:: ExprKind :: Lit ( _) )
761- }
762- _ => false ,
763- } ,
764- _ => false ,
765- } ,
766750 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
767751 MetaVarKind :: Literal => true ,
768752 MetaVarKind :: Expr { can_begin_literal_maybe_minus, .. } => {
@@ -777,14 +761,6 @@ impl Token {
777761 pub fn can_begin_string_literal ( & self ) -> bool {
778762 match self . uninterpolate ( ) . kind {
779763 Literal ( ..) => true ,
780- Interpolated ( ref nt) => match & * * nt {
781- NtLiteral ( _) => true ,
782- NtExpr ( e) => match & e. kind {
783- ast:: ExprKind :: Lit ( _) => true ,
784- _ => false ,
785- } ,
786- _ => false ,
787- } ,
788764 OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
789765 MetaVarKind :: Literal => true ,
790766 MetaVarKind :: Expr { can_begin_string_literal, .. } => can_begin_string_literal,
@@ -848,13 +824,16 @@ impl Token {
848824
849825 /// Is this a pre-parsed expression dropped into the token stream
850826 /// (which happens while parsing the result of macro expansion)?
851- pub fn is_whole_expr ( & self ) -> bool {
827+ pub fn is_metavar_expr ( & self ) -> bool {
852828 #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
853829 if let Interpolated ( nt) = & self . kind
854- && let NtExpr ( _ ) | NtLiteral ( _ ) | NtBlock ( _) = & * * nt
830+ && let NtBlock ( _) = & * * nt
855831 {
856832 true
857- } else if matches ! ( self . is_metavar_seq( ) , Some ( MetaVarKind :: Path ) ) {
833+ } else if matches ! (
834+ self . is_metavar_seq( ) ,
835+ Some ( MetaVarKind :: Expr { .. } | MetaVarKind :: Literal | MetaVarKind :: Path )
836+ ) {
858837 true
859838 } else {
860839 false
@@ -863,6 +842,7 @@ impl Token {
863842
864843 /// Is the token an interpolated block (`$b:block`)?
865844 pub fn is_whole_block ( & self ) -> bool {
845+ #[ allow( irrefutable_let_patterns) ] // FIXME: temporary
866846 if let Interpolated ( nt) = & self . kind
867847 && let NtBlock ( ..) = & * * nt
868848 {
@@ -1063,8 +1043,6 @@ pub enum NtExprKind {
10631043/// For interpolation during macro expansion.
10641044pub enum Nonterminal {
10651045 NtBlock ( P < ast:: Block > ) ,
1066- NtExpr ( P < ast:: Expr > ) ,
1067- NtLiteral ( P < ast:: Expr > ) ,
10681046}
10691047
10701048#[ derive( Debug , Copy , Clone , PartialEq , Eq , Encodable , Decodable , Hash , HashStable_Generic ) ]
@@ -1154,15 +1132,12 @@ impl Nonterminal {
11541132 pub fn use_span ( & self ) -> Span {
11551133 match self {
11561134 NtBlock ( block) => block. span ,
1157- NtExpr ( expr) | NtLiteral ( expr) => expr. span ,
11581135 }
11591136 }
11601137
11611138 pub fn descr ( & self ) -> & ' static str {
11621139 match self {
11631140 NtBlock ( ..) => "block" ,
1164- NtExpr ( ..) => "expression" ,
1165- NtLiteral ( ..) => "literal" ,
11661141 }
11671142 }
11681143}
@@ -1181,8 +1156,6 @@ impl fmt::Debug for Nonterminal {
11811156 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
11821157 match * self {
11831158 NtBlock ( ..) => f. pad ( "NtBlock(..)" ) ,
1184- NtExpr ( ..) => f. pad ( "NtExpr(..)" ) ,
1185- NtLiteral ( ..) => f. pad ( "NtLiteral(..)" ) ,
11861159 }
11871160 }
11881161}
@@ -1205,7 +1178,7 @@ mod size_asserts {
12051178 // tidy-alphabetical-start
12061179 static_assert_size ! ( Lit , 12 ) ;
12071180 static_assert_size ! ( LitKind , 2 ) ;
1208- static_assert_size ! ( Nonterminal , 16 ) ;
1181+ static_assert_size ! ( Nonterminal , 8 ) ;
12091182 static_assert_size ! ( Token , 24 ) ;
12101183 static_assert_size ! ( TokenKind , 16 ) ;
12111184 // tidy-alphabetical-end
0 commit comments