1
Fork 0

Rollup merge of #137742 - mu001999-contrib:fix-137708, r=compiler-errors

unconditionally lower match arm even if it's unneeded for never pattern in match

fixes #137708

Lowering arm body is skipped when lowering match arm with never pattern, but we may need the HirId for DefId in the body in later passes. And then we got the ICE `No HirId for DefId`.

Fixes this by lowering the arm body even if it's unneeded for never pattern in match, so that we can generate HirId and use it then.

r? `@compiler-errors`
This commit is contained in:
Matthias Krüger 2025-03-01 05:49:56 +01:00 committed by GitHub
commit 472bc0ee25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 53 additions and 2 deletions

View file

@ -671,10 +671,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let span = self.lower_span(arm.span);
self.lower_attrs(hir_id, &arm.attrs, arm.span);
let is_never_pattern = pat.is_never_pattern();
let body = if let Some(body) = &arm.body
// We need to lower the body even if it's unneeded for never pattern in match,
// ensure that we can get HirId for DefId if need (issue #137708).
let body = arm.body.as_ref().map(|x| self.lower_expr(x));
let body = if let Some(body) = body
&& !is_never_pattern
{
self.lower_expr(body)
body
} else {
// Either `body.is_none()` or `is_never_pattern` here.
if !is_never_pattern {