Inline cond_needs_par into print_let

This commit is contained in:
David Tolnay 2023-11-29 21:09:27 -08:00
parent d2b7bd4774
commit 8d64961589
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 8 additions and 3 deletions

View File

@ -1161,8 +1161,13 @@ impl<'a> State<'a> {
self.word_space("=");
self.print_expr_cond_paren(
expr,
Self::cond_needs_par(expr)
|| parser::needs_par_as_let_scrutinee(expr.precedence().order()),
match expr.kind {
ast::ExprKind::Break(..)
| ast::ExprKind::Closure(..)
| ast::ExprKind::Ret(..)
| ast::ExprKind::Yeet(..) => true,
_ => parser::contains_exterior_struct_lit(expr),
} || parser::needs_par_as_let_scrutinee(expr.precedence().order()),
);
}

View File

@ -69,7 +69,7 @@ impl<'a> State<'a> {
///
/// These cases need parens due to the parse error observed in #26461: `if return {}`
/// parses as the erroneous construct `if (return {})`, not `if (return) {}`.
pub(super) fn cond_needs_par(expr: &ast::Expr) -> bool {
fn cond_needs_par(expr: &ast::Expr) -> bool {
match expr.kind {
ast::ExprKind::Break(..)
| ast::ExprKind::Closure(..)