Skip to content

Commit 770be24

Browse files
committed
Use DefIds to identify anon consts when converting from HIR to ty::Const
1 parent 3f89c38 commit 770be24

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/librustc/ty/sty.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,16 +2404,14 @@ static_assert_size!(Const<'_>, 48);
24042404
impl<'tcx> Const<'tcx> {
24052405
/// Literals and const generic parameters are eagerly converted to a constant, everything else
24062406
/// becomes `Unevaluated`.
2407-
pub fn from_hir_anon_const(
2408-
tcx: TyCtxt<'tcx>,
2409-
ast_const: &hir::AnonConst,
2410-
ty: Ty<'tcx>,
2411-
) -> &'tcx Self {
2412-
debug!("Const::from_hir_anon_const(id={:?}, ast_const={:?})", ast_const.hir_id, ast_const);
2407+
pub fn from_hir_anon_const(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Ty<'tcx>) -> &'tcx Self {
2408+
debug!("Const::from_hir_anon_const(id={:?})", def_id);
2409+
2410+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
24132411

2414-
let def_id = tcx.hir().local_def_id(ast_const.hir_id);
2412+
let body_id = tcx.hir().body_owned_by(hir_id);
24152413

2416-
let expr = &tcx.hir().body(ast_const.body).value;
2414+
let expr = &tcx.hir().body(body_id).value;
24172415

24182416
let lit_input = match expr.kind {
24192417
hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }),

src/librustc_mir_build/hair/cx/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
406406

407407
// Now comes the rote stuff:
408408
hir::ExprKind::Repeat(ref v, ref count) => {
409+
let count = cx.tcx.hir().local_def_id(count.hir_id);
409410
let count = ty::Const::from_hir_anon_const(cx.tcx, count, cx.tcx.types.usize);
410411

411412
ExprKind::Repeat { value: v.to_ref(), count }

src/librustc_typeck/astconv.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
780780
}
781781
}
782782
(GenericParamDefKind::Const, GenericArg::Const(ct)) => {
783-
ty::Const::from_hir_anon_const(tcx, &ct.value, tcx.type_of(param.def_id)).into()
783+
let ct = tcx.hir().local_def_id(ct.value.hir_id);
784+
ty::Const::from_hir_anon_const(tcx, ct, tcx.type_of(param.def_id)).into()
784785
}
785786
_ => unreachable!(),
786787
},
@@ -2764,6 +2765,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27642765
.unwrap_or(tcx.types.err)
27652766
}
27662767
hir::TyKind::Array(ref ty, ref length) => {
2768+
let length = tcx.hir().local_def_id(length.hir_id);
27672769
let length = ty::Const::from_hir_anon_const(tcx, length, tcx.types.usize);
27682770
let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(&ty), length));
27692771
self.normalize_ty(ast_ty.span, array_ty)

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3280,7 +3280,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32803280
}
32813281

32823282
pub fn to_const(&self, ast_c: &hir::AnonConst, ty: Ty<'tcx>) -> &'tcx ty::Const<'tcx> {
3283-
ty::Const::from_hir_anon_const(self.tcx, ast_c, ty)
3283+
let c = self.tcx.hir().local_def_id(ast_c.hir_id);
3284+
ty::Const::from_hir_anon_const(self.tcx, c, ty)
32843285
}
32853286

32863287
// If the type given by the user has free regions, save it for later, since

0 commit comments

Comments
 (0)