summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/expr.rs
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2023-11-27 03:15:56 +0100
committerNadrieril <nadrieril+git@gmail.com>2023-12-03 12:25:46 +0100
commit80bdcbf50a63845dd3cfeb05751ba3dcbd1025b8 (patch)
tree3309db5b82d4bc8d8d30ffd0e02d96137f5853f9 /compiler/rustc_ast_lowering/src/expr.rs
parentcaa488b96e65131e4d70f219d5e89008031f9229 (diff)
downloadrust-80bdcbf50a63845dd3cfeb05751ba3dcbd1025b8.tar.gz
rust-80bdcbf50a63845dd3cfeb05751ba3dcbd1025b8.zip
Parse a pattern with no arm
Diffstat (limited to 'compiler/rustc_ast_lowering/src/expr.rs')
-rw-r--r--compiler/rustc_ast_lowering/src/expr.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs
index be5671f1bf7..b688950f5a3 100644
--- a/compiler/rustc_ast_lowering/src/expr.rs
+++ b/compiler/rustc_ast_lowering/src/expr.rs
@@ -566,13 +566,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
         });
         let hir_id = self.next_id();
         self.lower_attrs(hir_id, &arm.attrs);
-        hir::Arm {
-            hir_id,
-            pat,
-            guard,
-            body: self.lower_expr(&arm.body),
-            span: self.lower_span(arm.span),
-        }
+        let body = if let Some(body) = &arm.body {
+            self.lower_expr(body)
+        } else {
+            // An arm without a body, meant for never patterns.
+            // We add a fake `loop {}` arm body so that it typecks to `!`.
+            // FIXME(never_patterns): Desugar into a call to `unreachable_unchecked`.
+            let span = pat.span;
+            let block = self.arena.alloc(hir::Block {
+                stmts: &[],
+                expr: None,
+                hir_id: self.next_id(),
+                rules: hir::BlockCheckMode::DefaultBlock,
+                span,
+                targeted_by_break: false,
+            });
+            self.arena.alloc(hir::Expr {
+                hir_id: self.next_id(),
+                kind: hir::ExprKind::Loop(block, None, hir::LoopSource::Loop, span),
+                span,
+            })
+        };
+        hir::Arm { hir_id, pat, guard, body, span: self.lower_span(arm.span) }
     }
 
     /// Lower an `async` construct to a coroutine that implements `Future`.