mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 16:37:36 +00:00
Improve pretty printing of if/else.
By removing some of the over-indenting. AST pretty printing now looks correct. HIR pretty printing is better, but still over-indents some.
This commit is contained in:
parent
ee43aa356a
commit
e37c367482
@ -21,7 +21,7 @@ impl<'a> State<'a> {
|
|||||||
match &_else.kind {
|
match &_else.kind {
|
||||||
// Another `else if` block.
|
// Another `else if` block.
|
||||||
ast::ExprKind::If(i, then, e) => {
|
ast::ExprKind::If(i, then, e) => {
|
||||||
self.cbox(INDENT_UNIT);
|
self.cbox(0);
|
||||||
self.ibox(0);
|
self.ibox(0);
|
||||||
self.word(" else if ");
|
self.word(" else if ");
|
||||||
self.print_expr_as_cond(i);
|
self.print_expr_as_cond(i);
|
||||||
@ -31,7 +31,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
// Final `else` block.
|
// Final `else` block.
|
||||||
ast::ExprKind::Block(b, _) => {
|
ast::ExprKind::Block(b, _) => {
|
||||||
self.cbox(INDENT_UNIT);
|
self.cbox(0);
|
||||||
self.ibox(0);
|
self.ibox(0);
|
||||||
self.word(" else ");
|
self.word(" else ");
|
||||||
self.print_block(b)
|
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>) {
|
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.print_expr_as_cond(test);
|
||||||
self.space();
|
self.space();
|
||||||
self.print_block(blk);
|
self.print_block(blk);
|
||||||
|
@ -1065,7 +1065,7 @@ impl<'a> State<'a> {
|
|||||||
match els_inner.kind {
|
match els_inner.kind {
|
||||||
// Another `else if` block.
|
// Another `else if` block.
|
||||||
hir::ExprKind::If(i, then, e) => {
|
hir::ExprKind::If(i, then, e) => {
|
||||||
self.cbox(INDENT_UNIT);
|
self.cbox(0);
|
||||||
self.ibox(0);
|
self.ibox(0);
|
||||||
self.word(" else if ");
|
self.word(" else if ");
|
||||||
self.print_expr_as_cond(i);
|
self.print_expr_as_cond(i);
|
||||||
@ -1075,7 +1075,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
// Final `else` block.
|
// Final `else` block.
|
||||||
hir::ExprKind::Block(b, _) => {
|
hir::ExprKind::Block(b, _) => {
|
||||||
self.cbox(INDENT_UNIT);
|
self.cbox(0);
|
||||||
self.ibox(0);
|
self.ibox(0);
|
||||||
self.word(" else ");
|
self.word(" else ");
|
||||||
self.print_block(b);
|
self.print_block(b);
|
||||||
@ -1094,7 +1094,9 @@ impl<'a> State<'a> {
|
|||||||
blk: &hir::Expr<'_>,
|
blk: &hir::Expr<'_>,
|
||||||
elseopt: Option<&hir::Expr<'_>>,
|
elseopt: Option<&hir::Expr<'_>>,
|
||||||
) {
|
) {
|
||||||
self.head("if");
|
self.cbox(0);
|
||||||
|
self.ibox(0);
|
||||||
|
self.word_nbsp("if");
|
||||||
self.print_expr_as_cond(test);
|
self.print_expr_as_cond(test);
|
||||||
self.space();
|
self.space();
|
||||||
self.print_expr(blk);
|
self.print_expr(blk);
|
||||||
|
Loading…
Reference in New Issue
Block a user