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;
}
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
index 956200d..6a5bba3 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs
@@ -320,7 +320,9 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
self.print_ident(label.ident);
self.word_space(":");
}
- self.head("while");
+ self.cbox(0);
+ self.ibox(0);
+ self.word_nbsp("while");
self.print_expr_as_cond(test);
self.space();
self.print_block_with_attrs(blk, attrs);
@@ -330,7 +332,9 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
self.print_ident(label.ident);
self.word_space(":");
}
- self.head("for");
+ self.cbox(0);
+ self.ibox(0);
+ self.word_nbsp("for");
self.print_pat(pat);
self.space();
self.word_space("in");
@@ -343,12 +347,14 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
self.print_ident(label.ident);
self.word_space(":");
}
- self.head("loop");
+ self.cbox(0);
+ self.ibox(0);
+ self.word_nbsp("loop");
self.print_block_with_attrs(blk, attrs);
}
ast::ExprKind::Match(ref expr, ref arms) => {
- self.cbox(INDENT_UNIT);
- self.ibox(INDENT_UNIT);
+ self.cbox(0);
+ self.ibox(0);
self.word_nbsp("match");
self.print_expr_as_cond(expr);
self.space();
@@ -388,7 +394,7 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
self.word_space(":");
}
// containing cbox, will be closed by print-block at }
- self.cbox(INDENT_UNIT);
+ self.cbox(0);
// head-box, will be closed by print-block after {
self.ibox(0);
self.print_block_with_attrs(blk, attrs);
@@ -397,7 +403,7 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
self.word_nbsp("async");
self.print_capture_clause(capture_clause);
// cbox/ibox in analogy to the `ExprKind::Block` arm above
- self.cbox(INDENT_UNIT);
+ self.cbox(0);
self.ibox(0);
self.print_block_with_attrs(blk, attrs);
}
@@ -500,7 +506,9 @@ pub(super) fn print_expr_outer_attr_style(&mut self, expr: &ast::Expr, is_inline
self.word("?")
}
ast::ExprKind::TryBlock(ref blk) => {
- self.head("try");
+ self.cbox(0);
+ self.ibox(0);
+ self.word_nbsp("try");
self.print_block_with_attrs(blk, attrs)
}
ast::ExprKind::Err => {
diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs
index e575d6a..dac84ae 100644
--- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs
+++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs
@@ -1,5 +1,5 @@
use crate::pp::Breaks::Inconsistent;
-use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
+use crate::pprust::state::{AnnNode, PrintState, State};
use rustc_ast as ast;
use rustc_ast::GenericBound;
@@ -377,7 +377,7 @@ fn print_variants(&mut self, variants: &[ast::Variant], span: rustc_span::Span)
self.space_if_not_bol();
self.maybe_print_comment(v.span.lo());
self.print_outer_attributes(&v.attrs);
- self.ibox(INDENT_UNIT);
+ self.ibox(0);
self.print_variant(v);
self.word(",");
self.end();