diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-27 16:08:59 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-27 16:08:59 +0200 |
| commit | 405c8afce315639b45a949c4d6a05321f043665d (patch) | |
| tree | 0ed01b036f266168080f8a42854bf80b11e124ad /compiler/rustc_ast_pretty | |
| parent | 4f7aed6791027bb57c5bdd8ffbd95ddb731f2397 (diff) | |
| parent | 7ac2d1f1bdb2348b13eb4f5fb9c7d620e316034f (diff) | |
| download | rust-405c8afce315639b45a949c4d6a05321f043665d.tar.gz rust-405c8afce315639b45a949c4d6a05321f043665d.zip | |
Rollup merge of #140280 - nnethercote:improve-if-else-printing, r=Urgau
Improve if/else pretty printing AST/HIR pretty printing of if/else is currently pretty bad. This PR improves it a lot. r? `@Nadrieril`
Diffstat (limited to 'compiler/rustc_ast_pretty')
| -rw-r--r-- | compiler/rustc_ast_pretty/src/pprust/state/expr.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index 4aeb7c00995..48da9fc63b8 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -21,7 +21,7 @@ impl<'a> State<'a> { match &_else.kind { // Another `else if` block. ast::ExprKind::If(i, then, e) => { - self.cbox(INDENT_UNIT - 1); + self.cbox(0); self.ibox(0); self.word(" else if "); self.print_expr_as_cond(i); @@ -30,8 +30,8 @@ impl<'a> State<'a> { self.print_else(e.as_deref()) } // Final `else` block. - ast::ExprKind::Block(b, _) => { - self.cbox(INDENT_UNIT - 1); + ast::ExprKind::Block(b, None) => { + self.cbox(0); self.ibox(0); self.word(" else "); self.print_block(b) @@ -45,7 +45,9 @@ impl<'a> State<'a> { } fn print_if(&mut self, test: &ast::Expr, blk: &ast::Block, elseopt: Option<&ast::Expr>) { - self.head("if"); + self.cbox(0); + self.ibox(0); + self.word_nbsp("if"); self.print_expr_as_cond(test); self.space(); self.print_block(blk); |
