Skip to content

Commit 28e3022

Browse files
committed
Accept LocalDefId as key for mir_borrowck query
1 parent 6a5b281 commit 28e3022

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

src/librustc_interface/passes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
834834
});
835835

836836
sess.time("MIR_borrow_checking", || {
837-
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id.to_def_id()));
837+
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
838838
});
839839

840840
sess.time("dumping_chalk_like_clauses", || {

src/librustc_middle/query/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,11 @@ rustc_queries! {
494494
BorrowChecking {
495495
/// Borrow-checks the function body. If this is a closure, returns
496496
/// additional requirements that the closure's creator must verify.
497-
query mir_borrowck(key: DefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
498-
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key) }
497+
query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> {
498+
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) }
499499
cache_on_disk_if(tcx, opt_result) {
500-
key.is_local()
501-
&& (tcx.is_closure(key)
502-
|| opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty()))
500+
tcx.is_closure(key.to_def_id())
501+
|| opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty())
503502
}
504503
}
505504
}

src/librustc_mir/borrow_check/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ pub fn provide(providers: &mut Providers<'_>) {
9292
*providers = Providers { mir_borrowck, ..*providers };
9393
}
9494

95-
fn mir_borrowck(tcx: TyCtxt<'_>, def_id: DefId) -> &BorrowCheckResult<'_> {
96-
let (input_body, promoted) = tcx.mir_validated(def_id);
97-
debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id));
95+
fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &BorrowCheckResult<'_> {
96+
let (input_body, promoted) = tcx.mir_validated(def_id.to_def_id());
97+
debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id.to_def_id()));
9898

9999
let opt_closure_req = tcx.infer_ctxt().enter(|infcx| {
100100
let input_body: &Body<'_> = &input_body.borrow();
101101
let promoted: &IndexVec<_, _> = &promoted.borrow();
102-
do_mir_borrowck(&infcx, input_body, promoted, def_id.expect_local())
102+
do_mir_borrowck(&infcx, input_body, promoted, def_id)
103103
});
104104
debug!("mir_borrowck done");
105105

@@ -1268,7 +1268,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12681268
match **aggregate_kind {
12691269
AggregateKind::Closure(def_id, _) | AggregateKind::Generator(def_id, _, _) => {
12701270
let BorrowCheckResult { used_mut_upvars, .. } =
1271-
self.infcx.tcx.mir_borrowck(def_id);
1271+
self.infcx.tcx.mir_borrowck(def_id.expect_local());
12721272
debug!("{:?} used_mut_upvars={:?}", def_id, used_mut_upvars);
12731273
for field in used_mut_upvars {
12741274
self.propagate_closure_used_mut_upvar(&operands[field.index()]);

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::frozen::Frozen;
99
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1010
use rustc_errors::struct_span_err;
1111
use rustc_hir as hir;
12-
use rustc_hir::def_id::DefId;
12+
use rustc_hir::def_id::{DefId, LocalDefId};
1313
use rustc_index::vec::{Idx, IndexVec};
1414
use rustc_infer::infer::canonical::QueryRegionConstraints;
1515
use rustc_infer::infer::outlives::env::RegionBoundPairs;
@@ -2569,7 +2569,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25692569
// clauses on the struct.
25702570
AggregateKind::Closure(def_id, substs)
25712571
| AggregateKind::Generator(def_id, substs, _) => {
2572-
self.prove_closure_bounds(tcx, *def_id, substs, location)
2572+
self.prove_closure_bounds(tcx, def_id.expect_local(), substs, location)
25732573
}
25742574

25752575
AggregateKind::Array(_) | AggregateKind::Tuple => ty::InstantiatedPredicates::empty(),
@@ -2584,14 +2584,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25842584
fn prove_closure_bounds(
25852585
&mut self,
25862586
tcx: TyCtxt<'tcx>,
2587-
def_id: DefId,
2587+
def_id: LocalDefId,
25882588
substs: SubstsRef<'tcx>,
25892589
location: Location,
25902590
) -> ty::InstantiatedPredicates<'tcx> {
25912591
if let Some(ref closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements
25922592
{
25932593
let closure_constraints = QueryRegionConstraints {
2594-
outlives: closure_region_requirements.apply_requirements(tcx, def_id, substs),
2594+
outlives: closure_region_requirements.apply_requirements(
2595+
tcx,
2596+
def_id.to_def_id(),
2597+
substs,
2598+
),
25952599

25962600
// Presently, closures never propagate member
25972601
// constraints to their parents -- they are enforced

src/librustc_mir/transform/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &Body<'_> {
340340

341341
// (Mir-)Borrowck uses `mir_validated`, so we have to force it to
342342
// execute before we can steal.
343-
tcx.ensure().mir_borrowck(def_id);
343+
tcx.ensure().mir_borrowck(def_id.expect_local());
344344

345345
let (body, _) = tcx.mir_validated(def_id);
346346
let mut body = body.steal();
@@ -356,7 +356,7 @@ fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> &IndexVec<Promoted, Body<'_>>
356356
return tcx.intern_promoted(IndexVec::new());
357357
}
358358

359-
tcx.ensure().mir_borrowck(def_id);
359+
tcx.ensure().mir_borrowck(def_id.expect_local());
360360
let (_, promoted) = tcx.mir_validated(def_id);
361361
let mut promoted = promoted.steal();
362362

src/librustc_typeck/collect/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
114114
ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: Some(owner), origin, .. }) => {
115115
let concrete_types = match origin {
116116
OpaqueTyOrigin::FnReturn | OpaqueTyOrigin::AsyncFn => {
117-
&tcx.mir_borrowck(owner).concrete_opaque_types
117+
&tcx.mir_borrowck(owner.expect_local()).concrete_opaque_types
118118
}
119119
OpaqueTyOrigin::Misc => {
120120
// We shouldn't leak borrowck results through impl trait in bindings.

0 commit comments

Comments
 (0)