Skip to content

Commit e678f3d

Browse files
committed
Document MacCall special case in Parser::expr_is_complete
1 parent 923527a commit e678f3d

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

Lines changed: 44 additions & 7 deletions
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

@@ -381,9 +381,8 @@ impl<'a> Parser<'a> {
381381
Ok(lhs)
382382
}
383383

384-
#[allow(non_snake_case)]
385-
fn should_continue_as_assoc_expr_FIXME(&mut self, lhs: &Expr) -> bool {
386-
match (self.expr_is_complete_FIXME(lhs), AssocOp::from_token(&self.token)) {
384+
fn should_continue_as_assoc_expr(&mut self, lhs: &Expr) -> bool {
385+
match (self.expr_is_complete(lhs), AssocOp::from_token(&self.token)) {
387386
// Semi-statement forms are odd:
388387
// See https://github.com/rust-lang/rust/issues/29071
389388
(true, None) => false,
@@ -483,10 +482,48 @@ impl<'a> Parser<'a> {
483482
}
484483

485484
/// Checks if this expression is a successfully parsed statement.
486-
#[allow(non_snake_case)]
487-
fn expr_is_complete_FIXME(&self, e: &Expr) -> bool {
485+
///
486+
/// This determines whether to continue parsing more of an expression in a
487+
/// match arm (false) vs continue to the next arm (true).
488+
///
489+
/// ```ignore (illustrative)
490+
/// match ... {
491+
/// // Is this calling $e as a function, or is it the start of a new arm
492+
/// // with a tuple pattern?
493+
/// _ => $e (
494+
/// ^ )
495+
///
496+
/// // Is this an Index operation, or new arm with a slice pattern?
497+
/// _ => $e [
498+
/// ^ ]
499+
///
500+
/// // Is this a binary operator, or leading vert in a new arm? Same for
501+
/// // other punctuation which can either be a binary operator in
502+
/// // expression or unary operator in pattern, such as `&` and `-`.
503+
/// _ => $e |
504+
/// ^
505+
/// }
506+
/// ```
507+
///
508+
/// If $e is something like `path::to` or `(…)`, continue parsing the same
509+
/// arm.
510+
///
511+
/// If $e is something like `{}` or `if … {}`, then terminate the current
512+
/// arm and parse a new arm.
513+
fn expr_is_complete(&self, e: &Expr) -> bool {
488514
self.restrictions.contains(Restrictions::STMT_EXPR)
489515
&& match e.kind {
516+
// Surprising special case: even though braced macro calls like
517+
// `m! {}` normally introduce a statement boundary when found at
518+
// the head of a statement, in match arms they do not terminate
519+
// the arm.
520+
//
521+
// let _ = { m! {} () }; // macro call followed by unit
522+
//
523+
// match ... {
524+
// _ => m! {} (), // macro that expands to a function, which is then called
525+
// }
526+
//
490527
ExprKind::MacCall(_) => false,
491528
_ => !classify::expr_requires_semi_to_be_stmt(e),
492529
}
@@ -992,7 +1029,7 @@ impl<'a> Parser<'a> {
9921029
e = self.parse_dot_suffix_expr(lo, e)?;
9931030
continue;
9941031
}
995-
if self.expr_is_complete_FIXME(&e) {
1032+
if self.expr_is_complete(&e) {
9961033
return Ok(e);
9971034
}
9981035
e = match self.token.kind {

0 commit comments

Comments
 (0)