@@ -598,10 +598,11 @@ impl Token {
598598 /// **NB**: Take care when modifying this function, since it will change
599599 /// the stable set of tokens that are allowed to match an expr nonterminal.
600600 pub fn can_begin_expr ( & self ) -> bool {
601+ use Delimiter :: * ;
601602 match self . uninterpolate ( ) . kind {
602603 Ident ( name, is_raw) =>
603604 ident_can_begin_expr ( name, self . span , is_raw) , // value name or keyword
604- OpenDelim ( .. ) | // tuple, array or block
605+ OpenDelim ( Parenthesis | Brace | Bracket ) | // tuple, array or block
605606 Literal ( ..) | // literal
606607 Not | // operator not
607608 BinOp ( Minus ) | // unary minus
@@ -612,7 +613,7 @@ impl Token {
612613 // DotDotDot is no longer supported, but we need some way to display the error
613614 DotDot | DotDotDot | DotDotEq | // range notation
614615 Lt | BinOp ( Shl ) | // associated path
615- PathSep | // global path
616+ PathSep | // global path
616617 Lifetime ( ..) | // labeled loop
617618 Pound => true , // expression attributes
618619 Interpolated ( ref nt) =>
@@ -622,6 +623,12 @@ impl Token {
622623 NtLiteral ( ..) |
623624 NtPath ( ..)
624625 ) ,
626+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
627+ MetaVarKind :: Block |
628+ MetaVarKind :: Expr { .. } |
629+ MetaVarKind :: Literal |
630+ MetaVarKind :: Path
631+ ) ) ) => true ,
625632 _ => false ,
626633 }
627634 }
@@ -655,6 +662,14 @@ impl Token {
655662 | NtPath ( ..)
656663 | NtTy ( ..)
657664 ) ,
665+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
666+ MetaVarKind :: Expr { .. } |
667+ MetaVarKind :: Literal |
668+ MetaVarKind :: Meta |
669+ MetaVarKind :: Pat ( _) |
670+ MetaVarKind :: Path |
671+ MetaVarKind :: Ty
672+ ) ) ) => true ,
658673 _ => false ,
659674 }
660675 }
@@ -675,6 +690,10 @@ impl Token {
675690 Lt | BinOp ( Shl ) | // associated path
676691 PathSep => true , // global path
677692 Interpolated ( ref nt) => matches ! ( & * * nt, NtTy ( ..) | NtPath ( ..) ) ,
693+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
694+ MetaVarKind :: Ty |
695+ MetaVarKind :: Path
696+ ) ) ) => true ,
678697 // For anonymous structs or unions, which only appear in specific positions
679698 // (type of struct fields or union fields), we don't consider them as regular types
680699 _ => false ,
@@ -687,6 +706,9 @@ impl Token {
687706 OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
688707 Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
689708 Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
709+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
710+ MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
711+ ) ) ) => true ,
690712 _ => false ,
691713 }
692714 }
@@ -743,6 +765,13 @@ impl Token {
743765 } ,
744766 _ => false ,
745767 } ,
768+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
769+ MetaVarKind :: Literal => true ,
770+ MetaVarKind :: Expr { can_begin_literal_maybe_minus, .. } => {
771+ can_begin_literal_maybe_minus
772+ }
773+ _ => false ,
774+ } ,
746775 _ => false ,
747776 }
748777 }
@@ -758,6 +787,11 @@ impl Token {
758787 } ,
759788 _ => false ,
760789 } ,
790+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
791+ MetaVarKind :: Literal => true ,
792+ MetaVarKind :: Expr { can_begin_string_literal, .. } => can_begin_string_literal,
793+ _ => false ,
794+ } ,
761795 _ => false ,
762796 }
763797 }
0 commit comments