Improve HIR pretty-printing of if/else some more.
In the AST the "then" block is represented as a `Block`. In HIR the "then" block is represented as an `Expr` that happens to always be. `ExprKind::Block`. By deconstructing the `ExprKind::Block` to extract the block within, things print properly. For `issue-82392.rs`, note that we no longer print a type after the "then" block. This is good, it now matches how we don't print a type for the "else" block. (Well, we do print a type after the "else" block, but it's for the whole if/else.) Also tighten up some of the pattern matching -- these block expressions within if/else will never have labels.
This commit is contained in:
parent
e37c367482
commit
7ac2d1f1bd
4 changed files with 37 additions and 41 deletions
|
|
@ -12,37 +12,28 @@ fn f(x: 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 < 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 < 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); }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue