diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-03-01 05:49:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-01 05:49:56 +0100 |
| commit | 472bc0ee257ab6f387e5d9b9dd2a718372fa0c3a (patch) | |
| tree | 19efe26c3408dc914deb1069d5d130b001ab5abe /compiler | |
| parent | ecfb7d281159fe407e93ee33ca67825a8c3306a7 (diff) | |
| parent | d504f70ec9e56a49337173d384061d0b1cdd15e8 (diff) | |
| download | rust-472bc0ee257ab6f387e5d9b9dd2a718372fa0c3a.tar.gz rust-472bc0ee257ab6f387e5d9b9dd2a718372fa0c3a.zip | |
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`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/expr.rs | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index efbd1711daa..9c3db7abc1c 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -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 { |
