Rollup merge of #133779 - BoxyUwU:array_const_arg_infer_hir_id, r=compiler-errors

Use correct `hir_id` for array const arg infers

Fixes #133771

`self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by #133468, having no `HirId` associated with it. This then results in an ICE in metadata encoding. Fixing this then results in *another* ICE where `encode_defs` was not skipping encoding `type_of` and other queries for `DefId`s when they correspond to a `ConstArgKind::Infer` node.

This only reproduces with a library crate as metadata is not encoded for binaries, and apparently we had 0 tests for `generic_arg_infer` for array lengths in a library crate so this was not caught :<

cc #133589 `@voidc`

r? `@compiler-errors` `@lcnr`
This commit is contained in:
Matthias Krüger
2024-12-03 17:27:10 +01:00
committed by GitHub
3 changed files with 22 additions and 5 deletions

View File

@@ -2011,7 +2011,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ExprKind::Underscore => {
if self.tcx.features().generic_arg_infer() {
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind })
self.arena
.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
} else {
feature_err(
&self.tcx.sess,