Skip to content

Commit 9dbe33d

Browse files
committed
Document MacCall special case in Parser::expr_is_complete
1 parent 8adcaf5 commit 9dbe33d

File tree

1 file changed

+44
-7
lines changed
  • compiler/rustc_parse/src/parser

1 file changed

+44
-7
lines changed

compiler/rustc_parse/src/parser/expr.rs

+44-7
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl<'a> Parser<'a> {
190190
}
191191
};
192192

193-
if !self.should_continue_as_assoc_expr_FIXME(&lhs) {
193+
if !self.should_continue_as_assoc_expr(&lhs) {
194194
return Ok(lhs);
195195
}
196196

@@ -383,9 +383,8 @@ impl<'a> Parser<'a> {
383383
Ok(lhs)
384384
}
385385

386-
#[allow(non_snake_case)]
387-
fn should_continue_as_assoc_expr_FIXME(&mut self, lhs: &Expr) -> bool {
388-
match (self.expr_is_complete_FIXME(lhs), AssocOp::from_token(&self.token)) {
386+
fn should_continue_as_assoc_expr(&mut self, lhs: &Expr) -> bool {
387+
match (self.expr_is_complete(lhs), AssocOp::from_token(&self.token)) {
389388
// Semi-statement forms are odd:
390389
// See https://github.com/rust-lang/rust/issues/29071
391390
(true, None) => false,
@@ -497,10 +496,48 @@ impl<'a> Parser<'a> {
497496
}
498497

499498
/// Checks if this expression is a successfully parsed statement.
500-
#[allow(non_snake_case)]
501-
fn expr_is_complete_FIXME(&self, e: &Expr) -> bool {
499+
///
500+
/// This determines whether to continue parsing more of an expression in a
501+
/// match arm (false) vs continue to the next arm (true).
502+
///
503+
/// ```ignore (illustrative)
504+
/// match ... {
505+
/// // Is this calling $e as a function, or is it the start of a new arm
506+
/// // with a tuple pattern?
507+
/// _ => $e (
508+
/// ^ )
509+
///
510+
/// // Is this an Index operation, or new arm with a slice pattern?
511+
/// _ => $e [
512+
/// ^ ]
513+
///
514+
/// // Is this a binary operator, or leading vert in a new arm? Same for
515+
/// // other punctuation which can either be a binary operator in
516+
/// // expression or unary operator in pattern, such as `&` and `-`.
517+
/// _ => $e |
518+
/// ^
519+
/// }
520+
/// ```
521+
///
522+
/// If $e is something like `path::to` or `(…)`, continue parsing the same
523+
/// arm.
524+
///
525+
/// If $e is something like `{}` or `if … {}`, then terminate the current
526+
/// arm and parse a new arm.
527+
fn expr_is_complete(&self, e: &Expr) -> bool {
502528
self.restrictions.contains(Restrictions::STMT_EXPR)
503529
&& match e.kind {
530+
// Surprising special case: even though braced macro calls like
531+
// `m! {}` normally introduce a statement boundary when found at
532+
// the head of a statement, in match arms they do not terminate
533+
// the arm.
534+
//
535+
// let _ = { m! {} () }; // macro call followed by unit
536+
//
537+
// match ... {
538+
// _ => m! {} (), // macro that expands to a function, which is then called
539+
// }
540+
//
504541
ExprKind::MacCall(_) => false,
505542
_ => !classify::expr_requires_semi_to_be_stmt(e),
506543
}
@@ -1014,7 +1051,7 @@ impl<'a> Parser<'a> {
10141051
e = self.parse_dot_suffix_expr(lo, e)?;
10151052
continue;
10161053
}
1017-
if self.expr_is_complete_FIXME(&e) {
1054+
if self.expr_is_complete(&e) {
10181055
return Ok(e);
10191056
}
10201057
e = match self.token.kind {

0 commit comments

Comments
 (0)