Skip to content

Commit c80286d

Browse files
authored
Rollup merge of rust-lang#133779 - BoxyUwU:array_const_arg_infer_hir_id, r=compiler-errors
Use correct `hir_id` for array const arg infers Fixes rust-lang#133771 `self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by rust-lang#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 rust-lang#133589 `@voidc` r? `@compiler-errors` `@lcnr`
2 parents 6323109 + 2807ba7 commit c80286d

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20112011
ExprKind::Underscore => {
20122012
if self.tcx.features().generic_arg_infer() {
20132013
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
2014-
self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind })
2014+
self.arena
2015+
.alloc(hir::ConstArg { hir_id: self.lower_node_id(c.id), kind: ct_kind })
20152016
} else {
20162017
feature_err(
20172018
&self.tcx.sess,

compiler/rustc_metadata/src/rmeta/encoder.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1389,10 +1389,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13891389
// `ConstArgKind::Path`. We never actually access this `DefId`
13901390
// anywhere so we don't need to encode it for other crates.
13911391
if def_kind == DefKind::AnonConst
1392-
&& matches!(
1393-
tcx.hir_node_by_def_id(local_id),
1394-
hir::Node::ConstArg(hir::ConstArg { kind: hir::ConstArgKind::Path(..), .. })
1395-
)
1392+
&& match tcx.hir_node_by_def_id(local_id) {
1393+
hir::Node::ConstArg(hir::ConstArg { kind, .. }) => match kind {
1394+
// Skip encoding defs for these as they should not have had a `DefId` created
1395+
hir::ConstArgKind::Path(..) | hir::ConstArgKind::Infer(..) => true,
1396+
hir::ConstArgKind::Anon(..) => false,
1397+
},
1398+
_ => false,
1399+
}
13961400
{
13971401
continue;
13981402
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ check-pass
2+
3+
#![feature(generic_arg_infer)]
4+
#![crate_type = "lib"]
5+
6+
// Test that encoding the hallucinated `DefId` for the `_` const argument doesn't
7+
// ICE (see #133468). This requires this to be a library crate.
8+
9+
pub fn foo() {
10+
let s: [u8; 10];
11+
s = [0; _];
12+
}

0 commit comments

Comments
 (0)