1
Fork 0

Auto merge of #119284 - Nadrieril:fix-bodiless-arm-parse, r=cjgillot

Don't drop a hir node after lowering

Fixes https://github.com/rust-lang/rust/issues/119271.

It seems that all hir nodes that get allocated an id must be placed within the hir on pain of ICEs. In https://github.com/rust-lang/rust/pull/118527 I dropped guards on never patterns since they're not useful, which caused the ICE.
This commit is contained in:
bors 2023-12-30 22:44:33 +00:00
commit d868bc2842
3 changed files with 38 additions and 3 deletions

View file

@ -546,7 +546,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
let pat = self.lower_pat(&arm.pat);
let mut guard = arm.guard.as_ref().map(|cond| {
let guard = arm.guard.as_ref().map(|cond| {
if let ExprKind::Let(pat, scrutinee, span, is_recovered) = &cond.kind {
hir::Guard::IfLet(self.arena.alloc(hir::Let {
hir_id: self.next_id(),
@ -578,10 +578,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
} else if let Some(body) = &arm.body {
self.dcx().emit_err(NeverPatternWithBody { span: body.span });
guard = None;
} else if let Some(g) = &arm.guard {
self.dcx().emit_err(NeverPatternWithGuard { span: g.span });
guard = None;
}
// We add a fake `loop {}` arm body so that it typecks to `!`.