mirror of https://github.com/rust-lang/rust.git
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; }
This commit is contained in:
parent
cb93e9c0ec
commit
8ac05b9766
|
@ -320,7 +320,9 @@ impl<'a> State<'a> {
|
|||
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 @@ impl<'a> State<'a> {
|
|||
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 @@ impl<'a> State<'a> {
|
|||
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 @@ impl<'a> State<'a> {
|
|||
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 @@ impl<'a> State<'a> {
|
|||
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 @@ impl<'a> State<'a> {
|
|||
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 => {
|
||||
|
|
|
@ -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 @@ impl<'a> State<'a> {
|
|||
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();
|
||||
|
|
Loading…
Reference in New Issue