Rollup merge of #140280 - nnethercote:improve-if-else-printing, r=Urgau
Improve if/else pretty printing AST/HIR pretty printing of if/else is currently pretty bad. This PR improves it a lot. r? `@Nadrieril`
This commit is contained in:
commit
405c8afce3
9 changed files with 302 additions and 78 deletions
39
tests/pretty/hir-if-else.pp
Normal file
39
tests/pretty/hir-if-else.pp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#[prelude_import]
|
||||
use ::std::prelude::rust_2015::*;
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
//@ pretty-compare-only
|
||||
//@ pretty-mode:hir
|
||||
//@ pp-exact:hir-if-else.pp
|
||||
|
||||
fn f(x: u32,
|
||||
y:
|
||||
u32) {
|
||||
let mut a = 0;
|
||||
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; }
|
||||
|
||||
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); }
|
||||
59
tests/pretty/hir-if-else.rs
Normal file
59
tests/pretty/hir-if-else.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
//@ pretty-compare-only
|
||||
//@ pretty-mode:hir
|
||||
//@ pp-exact:hir-if-else.pp
|
||||
|
||||
fn f(x: u32, y: u32) {
|
||||
let mut a = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
52
tests/pretty/if-else.pp
Normal file
52
tests/pretty/if-else.pp
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#![feature(prelude_import)]
|
||||
#![no_std]
|
||||
#[prelude_import]
|
||||
use ::std::prelude::rust_2015::*;
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
//@ pretty-compare-only
|
||||
//@ pretty-mode:expanded
|
||||
//@ pp-exact:if-else.pp
|
||||
|
||||
fn f(x: u32, y: u32) {
|
||||
let mut a = 0;
|
||||
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; }
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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); }
|
||||
65
tests/pretty/if-else.rs
Normal file
65
tests/pretty/if-else.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//@ pretty-compare-only
|
||||
//@ pretty-mode:expanded
|
||||
//@ pp-exact:if-else.pp
|
||||
|
||||
fn f(x: u32, y: u32) {
|
||||
let mut a = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue