@@ -854,36 +854,11 @@ impl<'a> Parser<'a> {
854
854
_ => {
855
855
if self . eat_lt ( ) {
856
856
let ( qself, path) = self . parse_qpath ( PathStyle :: Expr ) ?;
857
- hi = path. span ;
857
+ let hi = path. span ;
858
858
return Ok ( self . mk_expr ( lo. to ( hi) , ExprKind :: Path ( Some ( qself) , path) , attrs) ) ;
859
859
}
860
860
if self . token . is_path_start ( ) {
861
- let path = self . parse_path ( PathStyle :: Expr ) ?;
862
-
863
- // `!`, as an operator, is prefix, so we know this isn't that.
864
- if self . eat ( & token:: Not ) {
865
- // MACRO INVOCATION expression
866
- let args = self . parse_mac_args ( ) ?;
867
- hi = self . prev_span ;
868
- ex = ExprKind :: Mac ( Mac {
869
- path,
870
- args,
871
- prior_type_ascription : self . last_type_ascription ,
872
- } ) ;
873
- } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
874
- if let Some ( expr) = self . maybe_parse_struct_expr ( lo, & path, & attrs) {
875
- return expr;
876
- } else {
877
- hi = path. span ;
878
- ex = ExprKind :: Path ( None , path) ;
879
- }
880
- } else {
881
- hi = path. span ;
882
- ex = ExprKind :: Path ( None , path) ;
883
- }
884
-
885
- let expr = self . mk_expr ( lo. to ( hi) , ex, attrs) ;
886
- return self . maybe_recover_from_bad_qpath ( expr, true ) ;
861
+ return self . parse_path_start_expr ( ) ;
887
862
}
888
863
if self . check_keyword ( kw:: Move ) || self . check_keyword ( kw:: Static ) {
889
864
return self . parse_closure_expr ( attrs) ;
@@ -1094,6 +1069,34 @@ impl<'a> Parser<'a> {
1094
1069
self . maybe_recover_from_bad_qpath ( expr, true )
1095
1070
}
1096
1071
1072
+ fn parse_path_start_expr ( & mut self ) -> PResult < ' a , P < Expr > > {
1073
+ let attrs = ThinVec :: new ( ) ;
1074
+ let lo = self . token . span ;
1075
+ let path = self . parse_path ( PathStyle :: Expr ) ?;
1076
+
1077
+ // `!`, as an operator, is prefix, so we know this isn't that.
1078
+ let ( hi, kind) = if self . eat ( & token:: Not ) {
1079
+ // MACRO INVOCATION expression
1080
+ let mac = Mac {
1081
+ path,
1082
+ args : self . parse_mac_args ( ) ?,
1083
+ prior_type_ascription : self . last_type_ascription ,
1084
+ } ;
1085
+ ( self . prev_span , ExprKind :: Mac ( mac) )
1086
+ } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
1087
+ if let Some ( expr) = self . maybe_parse_struct_expr ( lo, & path, & attrs) {
1088
+ return expr;
1089
+ } else {
1090
+ ( path. span , ExprKind :: Path ( None , path) )
1091
+ }
1092
+ } else {
1093
+ ( path. span , ExprKind :: Path ( None , path) )
1094
+ } ;
1095
+
1096
+ let expr = self . mk_expr ( lo. to ( hi) , kind, attrs) ;
1097
+ self . maybe_recover_from_bad_qpath ( expr, true )
1098
+ }
1099
+
1097
1100
/// Returns a string literal if the next token is a string literal.
1098
1101
/// In case of error returns `Some(lit)` if the next token is a literal with a wrong kind,
1099
1102
/// and returns `None` if the next token is not literal at all.
0 commit comments