mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 00:17:44 +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 {
|
||||
// Another `else if` block.
|
||||
ast::ExprKind::If(i, then, e) => {
|
||||
self.cbox(INDENT_UNIT);
|
||||
self.cbox(0);
|
||||
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);
|
||||
self.cbox(0);
|
||||
self.ibox(0);
|
||||
self.word(" else ");
|
||||
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>) {
|
||||
self.head("if");
|
||||
self.cbox(0);
|
||||
self.ibox(0);
|
||||
self.word_nbsp("if");
|
||||
self.print_expr_as_cond(test);
|
||||
self.space();
|
||||
self.print_block(blk);
|
||||
|
@ -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);
|
||||
self.cbox(0);
|
||||
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);
|
||||
self.cbox(0);
|
||||
self.ibox(0);
|
||||
self.word(" else ");
|
||||
self.print_block(b);
|
||||
@ -1094,7 +1094,9 @@ impl<'a> State<'a> {
|
||||
blk: &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.space();
|
||||
self.print_expr(blk);
|
||||
|
@ -12,37 +12,37 @@ fn f(x: u32,
|
||||
let mut a = 0;
|
||||
if x > y { a = 1; } else { a = 2; }
|
||||
|
||||
if x < 1
|
||||
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; }
|
||||
|
||||
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
|
||||
{
|
||||
a = 1;
|
||||
} else if x < 2
|
||||
{
|
||||
a = 2;
|
||||
} else if x < 3
|
||||
if x < 2
|
||||
{
|
||||
a = 3;
|
||||
} else if x < 4 { a = 4; } else { a = 5; }
|
||||
if x < 3
|
||||
{
|
||||
a += 1;
|
||||
} else if x < 4
|
||||
{ a += 1; if x < 5 { a += 1; } }
|
||||
} else if x < 6 { 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; } }
|
||||
}
|
||||
|
||||
fn main() { f(3, 4); }
|
||||
fn main() { f(3, 4); }
|
||||
|
@ -13,40 +13,40 @@ fn f(x: u32, y: u32) {
|
||||
if x > y { a = 1; } else { a = 2; }
|
||||
|
||||
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 = 1;
|
||||
} else if x < 2 {
|
||||
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;
|
||||
} 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;
|
||||
}
|
||||
|
||||
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 < 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); }
|
||||
|
@ -18,18 +18,18 @@ fn arbitrary_consuming_method_for_demonstration_purposes() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!(*{
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
__local_bind0
|
||||
} as usize)) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
__local_bind0
|
||||
} as usize)) {
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem as usize\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem as usize\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
fn addr_of() {
|
||||
@ -40,12 +40,12 @@ fn addr_of() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!&*__local_bind0) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: &elem\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: &elem\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
fn binary() {
|
||||
@ -56,12 +56,12 @@ fn binary() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!(*__local_bind0 == 1)) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem == 1\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem == 1\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
#[allow(unused_imports)]
|
||||
@ -69,12 +69,12 @@ fn binary() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!(*__local_bind0 >= 1)) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem >= 1\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem >= 1\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
#[allow(unused_imports)]
|
||||
@ -82,12 +82,12 @@ fn binary() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!(*__local_bind0 > 0)) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem > 0\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem > 0\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
#[allow(unused_imports)]
|
||||
@ -95,12 +95,12 @@ fn binary() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!(*__local_bind0 < 3)) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem < 3\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem < 3\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
#[allow(unused_imports)]
|
||||
@ -108,12 +108,12 @@ fn binary() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!(*__local_bind0 <= 3)) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem <= 3\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem <= 3\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
{
|
||||
#[allow(unused_imports)]
|
||||
@ -121,12 +121,12 @@ fn binary() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!(*__local_bind0 != 3)) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem != 3\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: elem != 3\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
fn unary() {
|
||||
@ -137,12 +137,12 @@ fn unary() {
|
||||
let mut __capture0 = ::core::asserting::Capture::new();
|
||||
let __local_bind0 = &elem;
|
||||
if ::core::intrinsics::unlikely(!**__local_bind0) {
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: *elem\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0);
|
||||
{
|
||||
::std::rt::panic_fmt(format_args!("Assertion failed: *elem\nWith captures:\n elem = {0:?}\n",
|
||||
__capture0));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
fn main() {}
|
||||
|
@ -9,9 +9,9 @@ extern crate std;
|
||||
|
||||
fn main() ({
|
||||
(if (true as bool)
|
||||
({ } as
|
||||
()) else if (let Some(a) =
|
||||
((Some as
|
||||
fn(i32) -> Option<i32> {Option::<i32>::Some})((3 as i32)) as
|
||||
Option<i32>) as bool) ({ } as ()) as ())
|
||||
} as ())
|
||||
({ } as
|
||||
()) else if (let Some(a) =
|
||||
((Some as
|
||||
fn(i32) -> Option<i32> {Option::<i32>::Some})((3 as i32)) as
|
||||
Option<i32>) as bool) ({ } as ()) as ())
|
||||
} as ())
|
||||
|
@ -32,12 +32,12 @@ fn main() {
|
||||
let mut iter =
|
||||
"\"world\"".parse::<crate::TokenStream>().unwrap().into_iter();
|
||||
if let (Some(crate::TokenTree::Literal(mut lit)), None) =
|
||||
(iter.next(), iter.next()) {
|
||||
lit.set_span(crate::Span::recover_proc_macro_span(2));
|
||||
lit
|
||||
} else {
|
||||
::core::panicking::panic("internal error: entered unreachable code")
|
||||
}
|
||||
(iter.next(), iter.next()) {
|
||||
lit.set_span(crate::Span::recover_proc_macro_span(2));
|
||||
lit
|
||||
} else {
|
||||
::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);
|
||||
@ -51,12 +51,12 @@ fn main() {
|
||||
let mut iter =
|
||||
"r#\"raw\"literal\"#".parse::<crate::TokenStream>().unwrap().into_iter();
|
||||
if let (Some(crate::TokenTree::Literal(mut lit)), None) =
|
||||
(iter.next(), iter.next()) {
|
||||
lit.set_span(crate::Span::recover_proc_macro_span(5));
|
||||
lit
|
||||
} else {
|
||||
::core::panicking::panic("internal error: entered unreachable code")
|
||||
}
|
||||
(iter.next(), iter.next()) {
|
||||
lit.set_span(crate::Span::recover_proc_macro_span(5));
|
||||
lit
|
||||
} else {
|
||||
::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);
|
||||
|
Loading…
Reference in New Issue
Block a user