@@ -598,10 +598,11 @@ impl Token {
598
598
/// **NB**: Take care when modifying this function, since it will change
599
599
/// the stable set of tokens that are allowed to match an expr nonterminal.
600
600
pub fn can_begin_expr ( & self ) -> bool {
601
+ use Delimiter :: * ;
601
602
match self . uninterpolate ( ) . kind {
602
603
Ident ( name, is_raw) =>
603
604
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
605
606
Literal ( ..) | // literal
606
607
Not | // operator not
607
608
BinOp ( Minus ) | // unary minus
@@ -612,7 +613,7 @@ impl Token {
612
613
// DotDotDot is no longer supported, but we need some way to display the error
613
614
DotDot | DotDotDot | DotDotEq | // range notation
614
615
Lt | BinOp ( Shl ) | // associated path
615
- PathSep | // global path
616
+ PathSep | // global path
616
617
Lifetime ( ..) | // labeled loop
617
618
Pound => true , // expression attributes
618
619
Interpolated ( ref nt) =>
@@ -622,6 +623,12 @@ impl Token {
622
623
NtLiteral ( ..) |
623
624
NtPath ( ..)
624
625
) ,
626
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
627
+ MetaVarKind :: Block |
628
+ MetaVarKind :: Expr { .. } |
629
+ MetaVarKind :: Literal |
630
+ MetaVarKind :: Path
631
+ ) ) ) => true ,
625
632
_ => false ,
626
633
}
627
634
}
@@ -655,6 +662,14 @@ impl Token {
655
662
| NtPath ( ..)
656
663
| NtTy ( ..)
657
664
) ,
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 ,
658
673
_ => false ,
659
674
}
660
675
}
@@ -675,6 +690,10 @@ impl Token {
675
690
Lt | BinOp ( Shl ) | // associated path
676
691
PathSep => true , // global path
677
692
Interpolated ( ref nt) => matches ! ( & * * nt, NtTy ( ..) | NtPath ( ..) ) ,
693
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
694
+ MetaVarKind :: Ty |
695
+ MetaVarKind :: Path
696
+ ) ) ) => true ,
678
697
// For anonymous structs or unions, which only appear in specific positions
679
698
// (type of struct fields or union fields), we don't consider them as regular types
680
699
_ => false ,
@@ -687,6 +706,9 @@ impl Token {
687
706
OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
688
707
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
689
708
Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
709
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
710
+ MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
711
+ ) ) ) => true ,
690
712
_ => false ,
691
713
}
692
714
}
@@ -743,6 +765,13 @@ impl Token {
743
765
} ,
744
766
_ => false ,
745
767
} ,
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
+ } ,
746
775
_ => false ,
747
776
}
748
777
}
@@ -758,6 +787,11 @@ impl Token {
758
787
} ,
759
788
_ => false ,
760
789
} ,
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
+ } ,
761
795
_ => false ,
762
796
}
763
797
}
0 commit comments