Use correct hir_id for array const arg infers · rust-lang/rust@2807ba7 (original) (raw)

File tree

3 files changed

lines changed

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -2013,7 +2013,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2013 2013 ExprKind::Underscore => {
2014 2014 if self.tcx.features().generic_arg_infer() {
2015 2015 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 })
2017 2018 } else {
2018 2019 feature_err(
2019 2020 &self.tcx.sess,
Original file line number Diff line number Diff line change
@@ -1389,10 +1389,14 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
1389 1389 // `ConstArgKind::Path`. We never actually access this `DefId`
1390 1390 // anywhere so we don't need to encode it for other crates.
1391 1391 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 +}
1396 1400 {
1397 1401 continue;
1398 1402 }
Original file line number Diff line number Diff 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 +}