Skip to content

Commit

Permalink
Accept m!{ .. }.method() and m!{ .. }? statements.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Sep 6, 2021
1 parent fbdff7f commit 3caf0bc
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions compiler/rustc_parse/src/parser/stmt.rs
Expand Up @@ -155,17 +155,20 @@ impl<'a> Parser<'a> {

let mac = MacCall { path, args, prior_type_ascription: self.last_type_ascription };

let kind = if delim == token::Brace || self.token == token::Semi || self.token == token::Eof
{
StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None }))
} else {
// Since none of the above applied, this is an expression statement macro.
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new());
let e = self.maybe_recover_from_bad_qpath(e, true)?;
let e = self.parse_dot_or_call_expr_with(e, lo, attrs.into())?;
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
StmtKind::Expr(e)
};
let kind =
if (delim == token::Brace && self.token != token::Dot && self.token != token::Question)
|| self.token == token::Semi
|| self.token == token::Eof
{
StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None }))
} else {
// Since none of the above applied, this is an expression statement macro.
let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac), AttrVec::new());
let e = self.maybe_recover_from_bad_qpath(e, true)?;
let e = self.parse_dot_or_call_expr_with(e, lo, attrs.into())?;
let e = self.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(e))?;
StmtKind::Expr(e)
};
Ok(self.mk_stmt(lo.to(hi), kind))
}

Expand Down

0 comments on commit 3caf0bc

Please sign in to comment.