From ee43aa356aa228b5cc8da41622855f4f2c07f8ab Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 25 Apr 2025 13:06:03 +1000 Subject: [PATCH] Fix some pretty printing indents. Indents for `cbox` and `ibox` are 0 or `INDENT_UNIT` (4) except for a couple of places which are `INDENT_UNIT - 1` for no clear reason. This commit changes the three space indents to four spaces. --- .../rustc_ast_pretty/src/pprust/state/expr.rs | 4 +- compiler/rustc_hir_pretty/src/lib.rs | 4 +- tests/pretty/hir-if-else.pp | 54 +++++++++---------- tests/pretty/if-else.pp | 36 ++++++------- tests/ui/match/issue-82392.stdout | 8 +-- tests/ui/proc-macro/quote/debug.stdout | 8 +-- 6 files changed, 57 insertions(+), 57 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index df848a26d390..37df567081fa 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(INDENT_UNIT); self.ibox(0); self.word(" else if "); self.print_expr_as_cond(i); @@ -31,7 +31,7 @@ impl<'a> State<'a> { } // Final `else` block. ast::ExprKind::Block(b, _) => { - self.cbox(INDENT_UNIT - 1); + self.cbox(INDENT_UNIT); self.ibox(0); self.word(" else "); self.print_block(b) diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index ff4385c3bcce..65b008dfc957 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -1065,7 +1065,7 @@ impl<'a> State<'a> { match els_inner.kind { // Another `else if` block. hir::ExprKind::If(i, then, e) => { - self.cbox(INDENT_UNIT - 1); + self.cbox(INDENT_UNIT); self.ibox(0); self.word(" else if "); self.print_expr_as_cond(i); @@ -1075,7 +1075,7 @@ impl<'a> State<'a> { } // Final `else` block. hir::ExprKind::Block(b, _) => { - self.cbox(INDENT_UNIT - 1); + self.cbox(INDENT_UNIT); self.ibox(0); self.word(" else "); self.print_block(b); diff --git a/tests/pretty/hir-if-else.pp b/tests/pretty/hir-if-else.pp index 551f24c69005..072e050d3e07 100644 --- a/tests/pretty/hir-if-else.pp +++ b/tests/pretty/hir-if-else.pp @@ -16,33 +16,33 @@ fn f(x: u32, { a = 1; } else if x < 2 - { - a = 2; - } else if x < 3 - { - a = 3; - } else if x < 4 { a = 4; } else { a = 5; } + { + a = 2; + } else if x < 3 + { + a = 3; + } else if x < 4 { a = 4; } else { a = 5; } - if x < y - { - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - } else { a += 1; a += 1; a += 1; a += 1; a += 1; a += 1; } + if x < y + { + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + } else { a += 1; a += 1; a += 1; a += 1; a += 1; a += 1; } - if x < 1 - { - if x < 2 - { - if x < 3 - { - a += 1; - } else if x < 4 - { a += 1; if x < 5 { a += 1; } } - } else if x < 6 { a += 1; } } - } + if x < 1 + { + if x < 2 + { + if x < 3 + { + a += 1; + } else if x < 4 + { a += 1; if x < 5 { a += 1; } } + } else if x < 6 { a += 1; } } + } - fn main() { f(3, 4); } + fn main() { f(3, 4); } diff --git a/tests/pretty/if-else.pp b/tests/pretty/if-else.pp index c70a78ade42f..14c715a8793d 100644 --- a/tests/pretty/if-else.pp +++ b/tests/pretty/if-else.pp @@ -15,30 +15,30 @@ fn f(x: u32, y: u32) { if x < 1 { a = 1; } else if x < 2 { - a = 2; - } else if x < 3 { a = 3; } else if x < 4 { a = 4; } else { a = 5; } + a = 2; + } else if x < 3 { a = 3; } else if x < 4 { a = 4; } else { a = 5; } if x < y { a += 1; a += 1; a += 1; } else { - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - a += 1; - } + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + a += 1; + } if x < 1 { if x < 2 { diff --git a/tests/ui/match/issue-82392.stdout b/tests/ui/match/issue-82392.stdout index 8b7edabf004e..34d2c7aa2ba5 100644 --- a/tests/ui/match/issue-82392.stdout +++ b/tests/ui/match/issue-82392.stdout @@ -11,7 +11,7 @@ fn main() ({ (if (true as bool) ({ } as ()) else if (let Some(a) = - ((Some as - fn(i32) -> Option {Option::::Some})((3 as i32)) as - Option) as bool) ({ } as ()) as ()) - } as ()) + ((Some as + fn(i32) -> Option {Option::::Some})((3 as i32)) as + Option) as bool) ({ } as ()) as ()) + } as ()) diff --git a/tests/ui/proc-macro/quote/debug.stdout b/tests/ui/proc-macro/quote/debug.stdout index 6ebb3a379511..b2a9f031b289 100644 --- a/tests/ui/proc-macro/quote/debug.stdout +++ b/tests/ui/proc-macro/quote/debug.stdout @@ -36,8 +36,8 @@ fn main() { lit.set_span(crate::Span::recover_proc_macro_span(2)); lit } else { - ::core::panicking::panic("internal error: entered unreachable code") - } + ::core::panicking::panic("internal error: entered unreachable code") + } }), &mut ts); crate::ToTokens::to_tokens(&crate::TokenTree::Punct(crate::Punct::new(';', crate::Spacing::Alone)), &mut ts); @@ -55,8 +55,8 @@ fn main() { lit.set_span(crate::Span::recover_proc_macro_span(5)); lit } else { - ::core::panicking::panic("internal error: entered unreachable code") - } + ::core::panicking::panic("internal error: entered unreachable code") + } }), &mut ts); crate::ToTokens::to_tokens(&crate::TokenTree::Punct(crate::Punct::new(';', crate::Spacing::Alone)), &mut ts);