Skip to content

Commit 2807ba7

Browse files
committed
Use correct hir_id for array const arg infers
1 parent d49be02 commit 2807ba7

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Diff for: compiler/rustc_ast_lowering/src/lib.rs

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

Diff for: 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)