Skip to content

Commit 24f0778

Browse files
authored
Rollup merge of rust-lang#64120 - nnethercote:move-path-parsing-earlier, r=petrochenkov
Move path parsing earlier It's a hot enough path that moving it slightly earlier gives a tiny but easy speedup. r? @petrochenkov
2 parents 8ef11fc + 8c74eb7 commit 24f0778

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/libsyntax/parse/parser/expr.rs

+30-26
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,36 @@ impl<'a> Parser<'a> {
889889
hi = path.span;
890890
return Ok(self.mk_expr(lo.to(hi), ExprKind::Path(Some(qself), path), attrs));
891891
}
892+
if self.token.is_path_start() {
893+
let path = self.parse_path(PathStyle::Expr)?;
894+
895+
// `!`, as an operator, is prefix, so we know this isn't that
896+
if self.eat(&token::Not) {
897+
// MACRO INVOCATION expression
898+
let (delim, tts) = self.expect_delimited_token_tree()?;
899+
hi = self.prev_span;
900+
ex = ExprKind::Mac(Mac {
901+
path,
902+
tts,
903+
delim,
904+
span: lo.to(hi),
905+
prior_type_ascription: self.last_type_ascription,
906+
});
907+
} else if self.check(&token::OpenDelim(token::Brace)) {
908+
if let Some(expr) = self.maybe_parse_struct_expr(lo, &path, &attrs) {
909+
return expr;
910+
} else {
911+
hi = path.span;
912+
ex = ExprKind::Path(None, path);
913+
}
914+
} else {
915+
hi = path.span;
916+
ex = ExprKind::Path(None, path);
917+
}
918+
919+
let expr = self.mk_expr(lo.to(hi), ex, attrs);
920+
return self.maybe_recover_from_bad_qpath(expr, true);
921+
}
892922
if self.check_keyword(kw::Move) || self.check_keyword(kw::Static) {
893923
return self.parse_lambda_expr(attrs);
894924
}
@@ -1007,32 +1037,6 @@ impl<'a> Parser<'a> {
10071037
let (await_hi, e_kind) = self.parse_incorrect_await_syntax(lo, self.prev_span)?;
10081038
hi = await_hi;
10091039
ex = e_kind;
1010-
} else if self.token.is_path_start() {
1011-
let path = self.parse_path(PathStyle::Expr)?;
1012-
1013-
// `!`, as an operator, is prefix, so we know this isn't that
1014-
if self.eat(&token::Not) {
1015-
// MACRO INVOCATION expression
1016-
let (delim, tts) = self.expect_delimited_token_tree()?;
1017-
hi = self.prev_span;
1018-
ex = ExprKind::Mac(Mac {
1019-
path,
1020-
tts,
1021-
delim,
1022-
span: lo.to(hi),
1023-
prior_type_ascription: self.last_type_ascription,
1024-
});
1025-
} else if self.check(&token::OpenDelim(token::Brace)) {
1026-
if let Some(expr) = self.maybe_parse_struct_expr(lo, &path, &attrs) {
1027-
return expr;
1028-
} else {
1029-
hi = path.span;
1030-
ex = ExprKind::Path(None, path);
1031-
}
1032-
} else {
1033-
hi = path.span;
1034-
ex = ExprKind::Path(None, path);
1035-
}
10361040
} else {
10371041
if !self.unclosed_delims.is_empty() && self.check(&token::Semi) {
10381042
// Don't complain about bare semicolons after unclosed braces

0 commit comments

Comments
 (0)