Fix pretty printer statement boundaries after braced macro call

This commit is contained in:
David Tolnay 2023-12-27 17:30:54 -08:00
parent c5a0eb1246
commit 7f2ffbdbc6
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 3 additions and 7 deletions

View file

@ -128,11 +128,7 @@ impl FixupContext {
/// The documentation on `FixupContext::leftmost_subexpression_in_stmt` has
/// examples.
pub fn would_cause_statement_boundary(self, expr: &Expr) -> bool {
self.leftmost_subexpression_in_stmt
&& match expr.kind {
ExprKind::MacCall(_) => false,
_ => !classify::expr_requires_semi_to_be_stmt(expr),
}
self.leftmost_subexpression_in_stmt && !classify::expr_requires_semi_to_be_stmt(expr)
}
/// Determine whether parentheses are needed around the given `let`

View file

@ -225,7 +225,7 @@ fn test_expr() {
);
c2_match_arm!(
[ m! {} - 1 ],
"match () { _ => m! {} - 1, }",
"match () { _ => (m! {}) - 1, }", // parenthesis is redundant
"match () { _ => m! {} - 1 }",
);
@ -747,7 +747,7 @@ fn test_stmt() {
);
c2_minus_one!(
[ m! {} ],
"m! {} - 1;", // FIXME(dtolnay): needs parens, otherwise this is 2 separate statements
"(m! {}) - 1;",
"m! {} - 1"
);