Handle pretty printing of else if let
clauses
Closes #84434. Closes #82329.
This commit is contained in:
parent
6df26f897c
commit
e4ce655cbf
1 changed files with 22 additions and 2 deletions
|
@ -1095,8 +1095,8 @@ impl<'a> State<'a> {
|
||||||
|
|
||||||
fn print_else(&mut self, els: Option<&hir::Expr<'_>>) {
|
fn print_else(&mut self, els: Option<&hir::Expr<'_>>) {
|
||||||
match els {
|
match els {
|
||||||
Some(_else) => {
|
Some(else_) => {
|
||||||
match _else.kind {
|
match else_.kind {
|
||||||
// "another else-if"
|
// "another else-if"
|
||||||
hir::ExprKind::If(ref i, ref then, ref e) => {
|
hir::ExprKind::If(ref i, ref then, ref e) => {
|
||||||
self.cbox(INDENT_UNIT - 1);
|
self.cbox(INDENT_UNIT - 1);
|
||||||
|
@ -1114,6 +1114,26 @@ impl<'a> State<'a> {
|
||||||
self.s.word(" else ");
|
self.s.word(" else ");
|
||||||
self.print_block(&b)
|
self.print_block(&b)
|
||||||
}
|
}
|
||||||
|
hir::ExprKind::Match(ref expr, arms, _) => {
|
||||||
|
// else if let desugared to match
|
||||||
|
assert!(arms.len() == 2, "if let desugars to match with two arms");
|
||||||
|
|
||||||
|
self.s.word(" else ");
|
||||||
|
self.s.word("{");
|
||||||
|
|
||||||
|
self.cbox(INDENT_UNIT);
|
||||||
|
self.ibox(INDENT_UNIT);
|
||||||
|
self.word_nbsp("match");
|
||||||
|
self.print_expr_as_cond(&expr);
|
||||||
|
self.s.space();
|
||||||
|
self.bopen();
|
||||||
|
for arm in arms {
|
||||||
|
self.print_arm(arm);
|
||||||
|
}
|
||||||
|
self.bclose(expr.span);
|
||||||
|
|
||||||
|
self.s.word("}");
|
||||||
|
}
|
||||||
// BLEAH, constraints would be great here
|
// BLEAH, constraints would be great here
|
||||||
_ => {
|
_ => {
|
||||||
panic!("print_if saw if with weird alternative");
|
panic!("print_if saw if with weird alternative");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue