Skip to content

Commit 8ac05b9

Browse files
committed
Fix some double indents on exprs containing blocks
The `print_expr` method already places an `ibox(INDENT_UNIT)` around every expr that gets printed. Some exprs were then using `self.head` inside of that, which does its own `cbox(INDENT_UNIT)`, resulting in two levels of indentation: while true { stuff; } This commit fixes those cases to produce the expected single level of indentation within every expression containing a block. while true { stuff; }
1 parent cb93e9c commit 8ac05b9

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

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

+16-8
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ impl<'a> State<'a> {
320320
self.print_ident(label.ident);
321321
self.word_space(":");
322322
}
323-
self.head("while");
323+
self.cbox(0);
324+
self.ibox(0);
325+
self.word_nbsp("while");
324326
self.print_expr_as_cond(test);
325327
self.space();
326328
self.print_block_with_attrs(blk, attrs);
@@ -330,7 +332,9 @@ impl<'a> State<'a> {
330332
self.print_ident(label.ident);
331333
self.word_space(":");
332334
}
333-
self.head("for");
335+
self.cbox(0);
336+
self.ibox(0);
337+
self.word_nbsp("for");
334338
self.print_pat(pat);
335339
self.space();
336340
self.word_space("in");
@@ -343,12 +347,14 @@ impl<'a> State<'a> {
343347
self.print_ident(label.ident);
344348
self.word_space(":");
345349
}
346-
self.head("loop");
350+
self.cbox(0);
351+
self.ibox(0);
352+
self.word_nbsp("loop");
347353
self.print_block_with_attrs(blk, attrs);
348354
}
349355
ast::ExprKind::Match(ref expr, ref arms) => {
350-
self.cbox(INDENT_UNIT);
351-
self.ibox(INDENT_UNIT);
356+
self.cbox(0);
357+
self.ibox(0);
352358
self.word_nbsp("match");
353359
self.print_expr_as_cond(expr);
354360
self.space();
@@ -388,7 +394,7 @@ impl<'a> State<'a> {
388394
self.word_space(":");
389395
}
390396
// containing cbox, will be closed by print-block at }
391-
self.cbox(INDENT_UNIT);
397+
self.cbox(0);
392398
// head-box, will be closed by print-block after {
393399
self.ibox(0);
394400
self.print_block_with_attrs(blk, attrs);
@@ -397,7 +403,7 @@ impl<'a> State<'a> {
397403
self.word_nbsp("async");
398404
self.print_capture_clause(capture_clause);
399405
// cbox/ibox in analogy to the `ExprKind::Block` arm above
400-
self.cbox(INDENT_UNIT);
406+
self.cbox(0);
401407
self.ibox(0);
402408
self.print_block_with_attrs(blk, attrs);
403409
}
@@ -500,7 +506,9 @@ impl<'a> State<'a> {
500506
self.word("?")
501507
}
502508
ast::ExprKind::TryBlock(ref blk) => {
503-
self.head("try");
509+
self.cbox(0);
510+
self.ibox(0);
511+
self.word_nbsp("try");
504512
self.print_block_with_attrs(blk, attrs)
505513
}
506514
ast::ExprKind::Err => {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::pp::Breaks::Inconsistent;
2-
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
2+
use crate::pprust::state::{AnnNode, PrintState, State};
33

44
use rustc_ast as ast;
55
use rustc_ast::GenericBound;
@@ -377,7 +377,7 @@ impl<'a> State<'a> {
377377
self.space_if_not_bol();
378378
self.maybe_print_comment(v.span.lo());
379379
self.print_outer_attributes(&v.attrs);
380-
self.ibox(INDENT_UNIT);
380+
self.ibox(0);
381381
self.print_variant(v);
382382
self.word(",");
383383
self.end();

0 commit comments

Comments
 (0)