Skip to content

Commit e4f6b8b

Browse files
committed
make subst_mir take EarlyBinder
1 parent 82f57c1 commit e4f6b8b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/rustc_middle/src/ty/instance.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -578,14 +578,15 @@ impl<'tcx> Instance<'tcx> {
578578
self.def.has_polymorphic_mir_body().then_some(self.substs)
579579
}
580580

581-
pub fn subst_mir<T>(&self, tcx: TyCtxt<'tcx>, v: &T) -> T
581+
pub fn subst_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<&T>) -> T
582582
where
583583
T: TypeFoldable<TyCtxt<'tcx>> + Copy,
584584
{
585+
let v = v.map_bound(|v| *v);
585586
if let Some(substs) = self.substs_for_mir_body() {
586-
EarlyBinder(*v).subst(tcx, substs)
587+
v.subst(tcx, substs)
587588
} else {
588-
*v
589+
v.subst_identity()
589590
}
590591
}
591592

compiler/rustc_mir_transform/src/inline.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ impl<'tcx> Inliner<'tcx> {
444444
work_list.push(target);
445445

446446
// If the place doesn't actually need dropping, treat it like a regular goto.
447-
let ty = callsite.callee.subst_mir(self.tcx, &place.ty(callee_body, tcx).ty);
447+
let ty = callsite
448+
.callee
449+
.subst_mir(self.tcx, ty::EarlyBinder(&place.ty(callee_body, tcx).ty));
448450
if ty.needs_drop(tcx, self.param_env) && let UnwindAction::Cleanup(unwind) = unwind {
449451
work_list.push(unwind);
450452
}
@@ -788,7 +790,9 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
788790
match terminator.kind {
789791
TerminatorKind::Drop { ref place, unwind, .. } => {
790792
// If the place doesn't actually need dropping, treat it like a regular goto.
791-
let ty = self.instance.subst_mir(tcx, &place.ty(self.callee_body, tcx).ty);
793+
let ty = self
794+
.instance
795+
.subst_mir(tcx, ty::EarlyBinder(&place.ty(self.callee_body, tcx).ty));
792796
if ty.needs_drop(tcx, self.param_env) {
793797
self.cost += CALL_PENALTY;
794798
if let UnwindAction::Cleanup(_) = unwind {
@@ -799,7 +803,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
799803
}
800804
}
801805
TerminatorKind::Call { func: Operand::Constant(ref f), unwind, .. } => {
802-
let fn_ty = self.instance.subst_mir(tcx, &f.literal.ty());
806+
let fn_ty = self.instance.subst_mir(tcx, ty::EarlyBinder(&f.literal.ty()));
803807
self.cost += if let ty::FnDef(def_id, _) = *fn_ty.kind() && tcx.is_intrinsic(def_id) {
804808
// Don't give intrinsics the extra penalty for calls
805809
INSTR_COST

0 commit comments

Comments
 (0)