Skip to content

Commit e4ce655

Browse files
committed
Handle pretty printing of else if let clauses
Closes #84434. Closes #82329.
1 parent 6df26f8 commit e4ce655

File tree

1 file changed

+22
-2
lines changed
  • compiler/rustc_hir_pretty/src

1 file changed

+22
-2
lines changed

compiler/rustc_hir_pretty/src/lib.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -1095,8 +1095,8 @@ impl<'a> State<'a> {
10951095

10961096
fn print_else(&mut self, els: Option<&hir::Expr<'_>>) {
10971097
match els {
1098-
Some(_else) => {
1099-
match _else.kind {
1098+
Some(else_) => {
1099+
match else_.kind {
11001100
// "another else-if"
11011101
hir::ExprKind::If(ref i, ref then, ref e) => {
11021102
self.cbox(INDENT_UNIT - 1);
@@ -1114,6 +1114,26 @@ impl<'a> State<'a> {
11141114
self.s.word(" else ");
11151115
self.print_block(&b)
11161116
}
1117+
hir::ExprKind::Match(ref expr, arms, _) => {
1118+
// else if let desugared to match
1119+
assert!(arms.len() == 2, "if let desugars to match with two arms");
1120+
1121+
self.s.word(" else ");
1122+
self.s.word("{");
1123+
1124+
self.cbox(INDENT_UNIT);
1125+
self.ibox(INDENT_UNIT);
1126+
self.word_nbsp("match");
1127+
self.print_expr_as_cond(&expr);
1128+
self.s.space();
1129+
self.bopen();
1130+
for arm in arms {
1131+
self.print_arm(arm);
1132+
}
1133+
self.bclose(expr.span);
1134+
1135+
self.s.word("}");
1136+
}
11171137
// BLEAH, constraints would be great here
11181138
_ => {
11191139
panic!("print_if saw if with weird alternative");

0 commit comments

Comments
 (0)