@@ -599,10 +599,11 @@ impl Token {
599
599
/// **NB**: Take care when modifying this function, since it will change
600
600
/// the stable set of tokens that are allowed to match an expr nonterminal.
601
601
pub fn can_begin_expr ( & self ) -> bool {
602
+ use Delimiter :: * ;
602
603
match self . uninterpolate ( ) . kind {
603
604
Ident ( name, is_raw) =>
604
605
ident_can_begin_expr ( name, self . span , is_raw) , // value name or keyword
605
- OpenDelim ( .. ) | // tuple, array or block
606
+ OpenDelim ( Parenthesis | Brace | Bracket ) | // tuple, array or block
606
607
Literal ( ..) | // literal
607
608
Not | // operator not
608
609
BinOp ( Minus ) | // unary minus
@@ -613,7 +614,7 @@ impl Token {
613
614
// DotDotDot is no longer supported, but we need some way to display the error
614
615
DotDot | DotDotDot | DotDotEq | // range notation
615
616
Lt | BinOp ( Shl ) | // associated path
616
- PathSep | // global path
617
+ PathSep | // global path
617
618
Lifetime ( ..) | // labeled loop
618
619
Pound => true , // expression attributes
619
620
Interpolated ( ref nt) =>
@@ -623,6 +624,12 @@ impl Token {
623
624
NtLiteral ( ..) |
624
625
NtPath ( ..)
625
626
) ,
627
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
628
+ MetaVarKind :: Block |
629
+ MetaVarKind :: Expr { .. } |
630
+ MetaVarKind :: Literal |
631
+ MetaVarKind :: Path
632
+ ) ) ) => true ,
626
633
_ => false ,
627
634
}
628
635
}
@@ -656,6 +663,14 @@ impl Token {
656
663
| NtPath ( ..)
657
664
| NtTy ( ..)
658
665
) ,
666
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
667
+ MetaVarKind :: Expr { .. } |
668
+ MetaVarKind :: Literal |
669
+ MetaVarKind :: Meta |
670
+ MetaVarKind :: Pat ( _) |
671
+ MetaVarKind :: Path |
672
+ MetaVarKind :: Ty
673
+ ) ) ) => true ,
659
674
_ => false ,
660
675
}
661
676
}
@@ -676,6 +691,10 @@ impl Token {
676
691
Lt | BinOp ( Shl ) | // associated path
677
692
PathSep => true , // global path
678
693
Interpolated ( ref nt) => matches ! ( & * * nt, NtTy ( ..) | NtPath ( ..) ) ,
694
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
695
+ MetaVarKind :: Ty |
696
+ MetaVarKind :: Path
697
+ ) ) ) => true ,
679
698
// For anonymous structs or unions, which only appear in specific positions
680
699
// (type of struct fields or union fields), we don't consider them as regular types
681
700
_ => false ,
@@ -688,6 +707,9 @@ impl Token {
688
707
OpenDelim ( Delimiter :: Brace ) | Literal ( ..) | BinOp ( Minus ) => true ,
689
708
Ident ( name, IdentIsRaw :: No ) if name. is_bool_lit ( ) => true ,
690
709
Interpolated ( ref nt) => matches ! ( & * * nt, NtExpr ( ..) | NtBlock ( ..) | NtLiteral ( ..) ) ,
710
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar (
711
+ MetaVarKind :: Expr { .. } | MetaVarKind :: Block | MetaVarKind :: Literal ,
712
+ ) ) ) => true ,
691
713
_ => false ,
692
714
}
693
715
}
@@ -744,6 +766,13 @@ impl Token {
744
766
} ,
745
767
_ => false ,
746
768
} ,
769
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
770
+ MetaVarKind :: Literal => true ,
771
+ MetaVarKind :: Expr { can_begin_literal_maybe_minus, .. } => {
772
+ can_begin_literal_maybe_minus
773
+ }
774
+ _ => false ,
775
+ } ,
747
776
_ => false ,
748
777
}
749
778
}
@@ -759,6 +788,11 @@ impl Token {
759
788
} ,
760
789
_ => false ,
761
790
} ,
791
+ OpenDelim ( Delimiter :: Invisible ( InvisibleOrigin :: MetaVar ( mv_kind) ) ) => match mv_kind {
792
+ MetaVarKind :: Literal => true ,
793
+ MetaVarKind :: Expr { can_begin_string_literal, .. } => can_begin_string_literal,
794
+ _ => false ,
795
+ } ,
762
796
_ => false ,
763
797
}
764
798
}
0 commit comments