Skip to content

Commit cb51d2d

Browse files
committed
Avoid more calls to typeck.
1 parent 0915d55 commit cb51d2d

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

compiler/rustc_borrowck/src/universal_regions.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_errors::Diagnostic;
1818
use rustc_hir as hir;
1919
use rustc_hir::def_id::{DefId, LocalDefId};
2020
use rustc_hir::lang_items::LangItem;
21-
use rustc_hir::{BodyOwnerKind, HirId};
21+
use rustc_hir::BodyOwnerKind;
2222
use rustc_index::vec::{Idx, IndexVec};
2323
use rustc_infer::infer::NllRegionVariableOrigin;
2424
use rustc_middle::ty::fold::TypeFoldable;
@@ -231,9 +231,7 @@ impl<'tcx> UniversalRegions<'tcx> {
231231
mir_def: ty::WithOptConstParam<LocalDefId>,
232232
param_env: ty::ParamEnv<'tcx>,
233233
) -> Self {
234-
let tcx = infcx.tcx;
235-
let mir_hir_id = tcx.hir().local_def_id_to_hir_id(mir_def.did);
236-
UniversalRegionsBuilder { infcx, mir_def, mir_hir_id, param_env }.build()
234+
UniversalRegionsBuilder { infcx, mir_def, param_env }.build()
237235
}
238236

239237
/// Given a reference to a closure type, extracts all the values
@@ -390,7 +388,6 @@ impl<'tcx> UniversalRegions<'tcx> {
390388
struct UniversalRegionsBuilder<'cx, 'tcx> {
391389
infcx: &'cx BorrowckInferCtxt<'cx, 'tcx>,
392390
mir_def: ty::WithOptConstParam<LocalDefId>,
393-
mir_hir_id: HirId,
394391
param_env: ty::ParamEnv<'tcx>,
395392
}
396393

@@ -560,12 +557,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
560557

561558
match tcx.hir().body_owner_kind(self.mir_def.did) {
562559
BodyOwnerKind::Closure | BodyOwnerKind::Fn => {
563-
let defining_ty = if self.mir_def.did.to_def_id() == typeck_root_def_id {
564-
tcx.type_of(typeck_root_def_id).subst_identity()
565-
} else {
566-
let tables = tcx.typeck(self.mir_def.did);
567-
tables.node_type(self.mir_hir_id)
568-
};
560+
let defining_ty = tcx.type_of(self.mir_def.def_id_for_type_of()).subst_identity();
569561

570562
debug!("defining_ty (pre-replacement): {:?}", defining_ty);
571563

@@ -594,7 +586,18 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
594586
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_substs);
595587
DefiningTy::Const(self.mir_def.did.to_def_id(), substs)
596588
} else {
597-
let ty = tcx.typeck(self.mir_def.did).node_type(self.mir_hir_id);
589+
// FIXME this line creates a dependency between borrowck and typeck.
590+
//
591+
// This is required for `AscribeUserType` canonical query, which will call
592+
// `type_of(inline_const_def_id)`. That `type_of` would inject erased lifetimes
593+
// into borrowck, which is ICE #78174.
594+
//
595+
// As a workaround, inline consts have an additional generic param (`ty`
596+
// below), so that `type_of(inline_const_def_id).substs(substs)` uses the
597+
// proper type with NLL infer vars.
598+
let ty = tcx
599+
.typeck(self.mir_def.did)
600+
.node_type(tcx.local_def_id_to_hir_id(self.mir_def.did));
598601
let substs = InlineConstSubsts::new(
599602
tcx,
600603
InlineConstSubstsParts { parent_substs: identity_substs, ty },

0 commit comments

Comments
 (0)