about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSmitty <me@smitop.com>2021-04-23 13:29:18 -0400
committerSmitty <me@smitop.com>2021-04-23 13:29:18 -0400
commite4ce655cbf11dded14af67a9d8201207c6d18c1f (patch)
treed39e9f0a4d7786eb78a737ef35fdf02de6633845
parent6df26f897cffb2d86880544bb451c6b5f8509b2d (diff)
downloadrust-e4ce655cbf11dded14af67a9d8201207c6d18c1f.tar.gz
rust-e4ce655cbf11dded14af67a9d8201207c6d18c1f.zip
Handle pretty printing of `else if let` clauses
Closes #84434. Closes #82329.
-rw-r--r--compiler/rustc_hir_pretty/src/lib.rs24
1 files changed, 22 insertions, 2 deletions
diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs
index 5820e7a2612..77d083fc5e9 100644
--- a/compiler/rustc_hir_pretty/src/lib.rs
+++ b/compiler/rustc_hir_pretty/src/lib.rs
@@ -1095,8 +1095,8 @@ impl<'a> State<'a> {
 
     fn print_else(&mut self, els: Option<&hir::Expr<'_>>) {
         match els {
-            Some(_else) => {
-                match _else.kind {
+            Some(else_) => {
+                match else_.kind {
                     // "another else-if"
                     hir::ExprKind::If(ref i, ref then, ref e) => {
                         self.cbox(INDENT_UNIT - 1);
@@ -1114,6 +1114,26 @@ impl<'a> State<'a> {
                         self.s.word(" else ");
                         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
                     _ => {
                         panic!("print_if saw if with weird alternative");