Skip to content

Commit 8d64961

Browse files
committed
Inline cond_needs_par into print_let
1 parent d2b7bd4 commit 8d64961

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,8 +1161,13 @@ impl<'a> State<'a> {
11611161
self.word_space("=");
11621162
self.print_expr_cond_paren(
11631163
expr,
1164-
Self::cond_needs_par(expr)
1165-
|| parser::needs_par_as_let_scrutinee(expr.precedence().order()),
1164+
match expr.kind {
1165+
ast::ExprKind::Break(..)
1166+
| ast::ExprKind::Closure(..)
1167+
| ast::ExprKind::Ret(..)
1168+
| ast::ExprKind::Yeet(..) => true,
1169+
_ => parser::contains_exterior_struct_lit(expr),
1170+
} || parser::needs_par_as_let_scrutinee(expr.precedence().order()),
11661171
);
11671172
}
11681173

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a> State<'a> {
6969
///
7070
/// These cases need parens due to the parse error observed in #26461: `if return {}`
7171
/// parses as the erroneous construct `if (return {})`, not `if (return) {}`.
72-
pub(super) fn cond_needs_par(expr: &ast::Expr) -> bool {
72+
fn cond_needs_par(expr: &ast::Expr) -> bool {
7373
match expr.kind {
7474
ast::ExprKind::Break(..)
7575
| ast::ExprKind::Closure(..)

0 commit comments

Comments
 (0)