Skip to content

Commit 5f0f86b

Browse files
committed
extract parse_path_start_expr
1 parent cb985ba commit 5f0f86b

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

src/librustc_parse/parser/expr.rs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -854,36 +854,11 @@ impl<'a> Parser<'a> {
854854
_ => {
855855
if self.eat_lt() {
856856
let (qself, path) = self.parse_qpath(PathStyle::Expr)?;
857-
hi = path.span;
857+
let hi = path.span;
858858
return Ok(self.mk_expr(lo.to(hi), ExprKind::Path(Some(qself), path), attrs));
859859
}
860860
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();
887862
}
888863
if self.check_keyword(kw::Move) || self.check_keyword(kw::Static) {
889864
return self.parse_closure_expr(attrs);
@@ -1094,6 +1069,34 @@ impl<'a> Parser<'a> {
10941069
self.maybe_recover_from_bad_qpath(expr, true)
10951070
}
10961071

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+
10971100
/// Returns a string literal if the next token is a string literal.
10981101
/// In case of error returns `Some(lit)` if the next token is a literal with a wrong kind,
10991102
/// and returns `None` if the next token is not literal at all.

0 commit comments

Comments
 (0)