Pretty-print let-else with added parenthesization when needed

This commit is contained in:
David Tolnay 2024-05-12 13:39:43 -07:00
parent 68854b798e
commit 94cc82c088
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 6 additions and 2 deletions

View File

@ -1238,7 +1238,11 @@ impl<'a> State<'a> {
if let Some((init, els)) = loc.kind.init_else_opt() {
self.nbsp();
self.word_space("=");
self.print_expr(init, FixupContext::default());
self.print_expr_cond_paren(
init,
els.is_some() && classify::expr_trailing_brace(init).is_some(),
FixupContext::default(),
);
if let Some(els) = els {
self.cbox(INDENT_UNIT);
self.ibox(INDENT_UNIT);

View File

@ -11,5 +11,5 @@ macro_rules! expr { ($e:expr) => { $e }; }
fn main() {
let _ = 1 + 1 else { return; };
let _ = loop {} else { return; };
let _ = (loop {}) else { return; };
}