diff options
| author | David Tolnay <dtolnay@gmail.com> | 2023-11-29 21:09:27 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2023-12-08 15:14:44 -0800 |
| commit | 8d649615894c869af4bab2419490dfb9a80ce2e2 (patch) | |
| tree | 7f254458c507327259ac7e5fe991a5361a310138 | |
| parent | d2b7bd4774d0c8bac5570f543f5c7eed130d17cd (diff) | |
| download | rust-8d649615894c869af4bab2419490dfb9a80ce2e2.tar.gz rust-8d649615894c869af4bab2419490dfb9a80ce2e2.zip | |
Inline cond_needs_par into print_let
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state/expr.rs | 2 |
2 files changed, 8 insertions, 3 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 946a69c54d1..ad5154ab251 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -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()), ); } diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index 5397278bbb1..b03e1c2c697 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -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(..) |
