Skip to content
/ rust Public
forked from rust-lang/rust

Commit 94cc82c

Browse files
committed
Pretty-print let-else with added parenthesization when needed
1 parent 68854b7 commit 94cc82c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,11 @@ impl<'a> State<'a> {
12381238
if let Some((init, els)) = loc.kind.init_else_opt() {
12391239
self.nbsp();
12401240
self.word_space("=");
1241-
self.print_expr(init, FixupContext::default());
1241+
self.print_expr_cond_paren(
1242+
init,
1243+
els.is_some() && classify::expr_trailing_brace(init).is_some(),
1244+
FixupContext::default(),
1245+
);
12421246
if let Some(els) = els {
12431247
self.cbox(INDENT_UNIT);
12441248
self.ibox(INDENT_UNIT);

tests/ui/unpretty/let-else.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ macro_rules! expr { ($e:expr) => { $e }; }
1111

1212
fn main() {
1313
let _ = 1 + 1 else { return; };
14-
let _ = loop {} else { return; };
14+
let _ = (loop {}) else { return; };
1515
}

0 commit comments

Comments
 (0)