Skip to content

Commit 1c8e593

Browse files
committed
Use the same path for Promoted and InlineConst DefiningTy.
1 parent ece7178 commit 1c8e593

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,6 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
546546
/// see `DefiningTy` for details.
547547
fn defining_ty(&self) -> DefiningTy<'tcx> {
548548
let tcx = self.infcx.tcx;
549-
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.to_def_id());
550549

551550
match tcx.hir().body_owner_kind(self.mir_def) {
552551
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
@@ -574,35 +573,15 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
574573

575574
BodyOwnerKind::Const | BodyOwnerKind::Static(..) => {
576575
match tcx.def_kind(self.mir_def) {
577-
DefKind::InlineConst => {
578-
// FIXME this line creates a dependency between borrowck and typeck.
579-
//
580-
// This is required for `AscribeUserType` canonical query, which will call
581-
// `type_of(inline_const_def_id)`. That `type_of` would inject erased lifetimes
582-
// into borrowck, which is ICE #78174.
583-
//
584-
// As a workaround, inline consts have an additional generic param (`ty`
585-
// below), so that `type_of(inline_const_def_id).substs(substs)` uses the
586-
// proper type with NLL infer vars.
587-
let ty = tcx
588-
.typeck(self.mir_def)
589-
.node_type(tcx.local_def_id_to_hir_id(self.mir_def));
590-
let identity_substs =
591-
InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
592-
let substs = InlineConstSubsts::new(
593-
tcx,
594-
InlineConstSubstsParts { parent_substs: identity_substs, ty },
595-
)
596-
.substs;
597-
let substs =
598-
self.infcx.replace_free_regions_with_nll_infer_vars(FR, substs);
599-
DefiningTy::InlineConst(self.mir_def.to_def_id(), substs)
600-
}
601-
DefKind::Promoted => {
602-
let body = tcx.mir_for_promoted(self.mir_def).borrow();
576+
DefKind::InlineConst | DefKind::Promoted => {
577+
// Fetch the actual type from MIR, as `type_of` returns something useless
578+
// like `<const_ty>`.
579+
let body = tcx.mir_promoted(self.mir_def).0.borrow();
603580
let ty = body.local_decls[RETURN_PLACE].ty;
604-
let parent_def_id = tcx.parent(self.mir_def.to_def_id());
605-
let parent_substs = InternalSubsts::identity_for_item(tcx, parent_def_id);
581+
582+
let typeck_root_def_id = tcx.typeck_root_def_id(self.mir_def.to_def_id());
583+
let parent_substs =
584+
InternalSubsts::identity_for_item(tcx, typeck_root_def_id);
606585
let substs = InlineConstSubsts::new(
607586
tcx,
608587
InlineConstSubstsParts { parent_substs, ty },

0 commit comments

Comments
 (0)