Skip to content

Commit b3c2aeb

Browse files
committed
rustc: push LocalDefId and/or assert_local calls farther back.
1 parent 9c1f88e commit b3c2aeb

File tree

16 files changed

+101
-92
lines changed

16 files changed

+101
-92
lines changed

src/librustc/middle/expr_use_visitor.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use self::ConsumeMode::*;
66
use self::OverloadedCallType::*;
77

88
use crate::hir::def::Res;
9-
use crate::hir::def_id::DefId;
9+
use crate::hir::def_id::{DefId, LocalDefId};
1010
use crate::hir::ptr::P;
1111
use crate::infer::InferCtxt;
1212
use crate::middle::mem_categorization as mc;
@@ -119,7 +119,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
119119
pub fn new(
120120
delegate: &'a mut (dyn Delegate<'tcx> + 'a),
121121
tcx: TyCtxt<'tcx>,
122-
body_owner: DefId,
122+
body_owner: LocalDefId,
123123
param_env: ty::ParamEnv<'tcx>,
124124
region_scope_tree: &'a region::ScopeTree,
125125
tables: &'a ty::TypeckTables<'tcx>,
@@ -140,7 +140,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
140140
pub fn with_infer(
141141
delegate: &'a mut (dyn Delegate<'tcx> + 'a),
142142
infcx: &'a InferCtxt<'a, 'tcx>,
143-
body_owner: DefId,
143+
body_owner: LocalDefId,
144144
param_env: ty::ParamEnv<'tcx>,
145145
region_scope_tree: &'a region::ScopeTree,
146146
tables: &'a ty::TypeckTables<'tcx>,
@@ -617,12 +617,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
617617
fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) {
618618
debug!("walk_captures({:?})", closure_expr);
619619

620-
let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id);
621-
if let Some(upvars) = self.tcx().upvars(closure_def_id) {
620+
let closure_def_id = self.tcx().hir().local_def_id(closure_expr.hir_id).assert_local();
621+
if let Some(upvars) = self.tcx().upvars(closure_def_id.to_def_id()) {
622622
for &var_id in upvars.keys() {
623623
let upvar_id = ty::UpvarId {
624624
var_path: ty::UpvarPath { hir_id: var_id },
625-
closure_expr_id: closure_def_id.assert_local(),
625+
closure_expr_id: closure_def_id,
626626
};
627627
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
628628
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,

src/librustc/middle/mem_categorization.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub use self::Note::*;
5959
use self::Aliasability::*;
6060

6161
use crate::middle::region;
62-
use crate::hir::def_id::DefId;
62+
use crate::hir::def_id::{DefId, LocalDefId};
6363
use crate::hir::Node;
6464
use crate::infer::InferCtxt;
6565
use crate::hir::def::{CtorOf, Res, DefKind, CtorKind};
@@ -214,7 +214,7 @@ impl HirNode for hir::Pat {
214214
pub struct MemCategorizationContext<'a, 'tcx> {
215215
pub tcx: TyCtxt<'tcx>,
216216
param_env: ty::ParamEnv<'tcx>,
217-
pub body_owner: DefId,
217+
pub body_owner: LocalDefId,
218218
pub upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
219219
pub region_scope_tree: &'a region::ScopeTree,
220220
pub tables: &'a ty::TypeckTables<'tcx>,
@@ -330,14 +330,14 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
330330
pub fn new(
331331
tcx: TyCtxt<'tcx>,
332332
param_env: ty::ParamEnv<'tcx>,
333-
body_owner: DefId,
333+
body_owner: LocalDefId,
334334
region_scope_tree: &'a region::ScopeTree,
335335
tables: &'a ty::TypeckTables<'tcx>,
336336
) -> MemCategorizationContext<'a, 'tcx> {
337337
MemCategorizationContext {
338338
tcx,
339339
body_owner,
340-
upvars: tcx.upvars(body_owner),
340+
upvars: tcx.upvars(body_owner.to_def_id()),
341341
region_scope_tree,
342342
tables,
343343
infcx: None,
@@ -359,7 +359,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
359359
pub fn with_infer(
360360
infcx: &'a InferCtxt<'a, 'tcx>,
361361
param_env: ty::ParamEnv<'tcx>,
362-
body_owner: DefId,
362+
body_owner: LocalDefId,
363363
region_scope_tree: &'a region::ScopeTree,
364364
tables: &'a ty::TypeckTables<'tcx>,
365365
) -> MemCategorizationContext<'a, 'tcx> {
@@ -368,7 +368,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
368368
MemCategorizationContext {
369369
tcx,
370370
body_owner,
371-
upvars: tcx.upvars(body_owner),
371+
upvars: tcx.upvars(body_owner.to_def_id()),
372372
region_scope_tree,
373373
tables,
374374
infcx: Some(infcx),
@@ -722,9 +722,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
722722
// FnOnce | copied | upvar -> &'up bk
723723

724724
let closure_expr_def_id = self.body_owner;
725-
let fn_hir_id = self.tcx.hir().local_def_id_to_hir_id(
726-
closure_expr_def_id.assert_local(),
727-
);
725+
let fn_hir_id = self.tcx.hir().local_def_id_to_hir_id(closure_expr_def_id);
728726
let ty = self.node_ty(fn_hir_id)?;
729727
let kind = match ty.kind {
730728
ty::Generator(..) => ty::ClosureKind::FnOnce,
@@ -747,7 +745,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
747745

748746
let upvar_id = ty::UpvarId {
749747
var_path: ty::UpvarPath { hir_id: var_id },
750-
closure_expr_id: closure_expr_def_id.assert_local(),
748+
closure_expr_id: closure_expr_def_id,
751749
};
752750

753751
let var_ty = self.node_ty(var_id)?;

src/librustc/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ rustc_queries! {
368368
desc { "type-checking all item bodies" }
369369
}
370370

371+
// FIXME(eddyb) take `LocalDefId` instead of `DefId` as key.
371372
query typeck_tables_of(key: DefId) -> &'tcx ty::TypeckTables<'tcx> {
372373
cache_on_disk_if { key.is_local() }
373374
load_cached(tcx, id) {
@@ -387,6 +388,7 @@ rustc_queries! {
387388
}
388389

389390
TypeChecking {
391+
// FIXME(eddyb) take `LocalDefId` instead of `DefId` as key.
390392
query has_typeck_tables(_: DefId) -> bool {}
391393

392394
query coherent_trait(def_id: DefId) -> () {
@@ -397,6 +399,7 @@ rustc_queries! {
397399
BorrowChecking {
398400
/// Borrow-checks the function body. If this is a closure, returns
399401
/// additional requirements that the closure's creator must verify.
402+
// FIXME(eddyb) take `LocalDefId` instead of `DefId` as key.
400403
query mir_borrowck(key: DefId) -> mir::BorrowCheckResult<'tcx> {
401404
cache_on_disk_if(tcx, _) { key.is_local() && tcx.is_closure(key) }
402405
}
@@ -489,6 +492,7 @@ rustc_queries! {
489492

490493
/// Per-body `region::ScopeTree`. The `DefId` should be the owner `DefId` for the body;
491494
/// in the case of closures, this will be redirected to the enclosing function.
495+
// FIXME(eddyb) take `LocalDefId` instead of `DefId` as key.
492496
query region_scope_tree(_: DefId) -> &'tcx region::ScopeTree {}
493497

494498
query mir_shims(key: ty::InstanceDef<'tcx>) -> &'tcx mir::Body<'tcx> {
@@ -879,6 +883,7 @@ rustc_queries! {
879883
desc { "generating a postorder list of CrateNums" }
880884
}
881885

886+
// FIXME(eddyb) take `LocalDefId` instead of `DefId` as key.
882887
query upvars(_: DefId) -> Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>> {
883888
eval_always
884889
}

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ pub struct UpvarBorrow<'tcx> {
829829
pub region: ty::Region<'tcx>,
830830
}
831831

832-
pub type UpvarListMap = FxHashMap<DefId, FxIndexMap<hir::HirId, UpvarId>>;
832+
pub type UpvarListMap = FxHashMap<LocalDefId, FxIndexMap<hir::HirId, UpvarId>>;
833833
pub type UpvarCaptureMap<'tcx> = FxHashMap<UpvarId, UpvarCapture<'tcx>>;
834834

835835
#[derive(Copy, Clone)]

src/librustc_mir/borrow_check/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,11 @@ fn do_mir_borrowck<'a, 'tcx>(
117117

118118
// Gather the upvars of a closure, if any.
119119
let tables = tcx.typeck_tables_of(def_id);
120+
// FIXME(eddyb) move this `assert_local` call further back,
121+
// replacing the `DefId` type (of `def_id`) with `LocalDefId`.
120122
let upvars: Vec<_> = tables
121123
.upvar_list
122-
.get(&def_id)
124+
.get(&def_id.assert_local())
123125
.into_iter()
124126
.flat_map(|v| v.values())
125127
.map(|upvar_id| {

src/librustc_mir/borrow_check/nll/region_infer/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::borrow_check::nll::{
1515
};
1616
use crate::borrow_check::Upvar;
1717

18-
use rustc::hir::def_id::DefId;
18+
use rustc::hir::def_id::{DefId, LocalDefId};
1919
use rustc::infer::canonical::QueryOutlivesConstraint;
2020
use rustc::infer::opaque_types;
2121
use rustc::infer::region_constraints::{GenericKind, VarInfos, VerifyBound};
@@ -1623,7 +1623,7 @@ pub trait ClosureRegionRequirementsExt<'tcx> {
16231623
fn apply_requirements(
16241624
&self,
16251625
tcx: TyCtxt<'tcx>,
1626-
closure_def_id: DefId,
1626+
closure_def_id: LocalDefId,
16271627
closure_substs: SubstsRef<'tcx>,
16281628
) -> Vec<QueryOutlivesConstraint<'tcx>>;
16291629

@@ -1653,7 +1653,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
16531653
fn apply_requirements(
16541654
&self,
16551655
tcx: TyCtxt<'tcx>,
1656-
closure_def_id: DefId,
1656+
closure_def_id: LocalDefId,
16571657
closure_substs: SubstsRef<'tcx>,
16581658
) -> Vec<QueryOutlivesConstraint<'tcx>> {
16591659
debug!(
@@ -1668,7 +1668,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
16681668
tcx,
16691669
closure_substs,
16701670
self.num_external_vids,
1671-
tcx.closure_base_def_id(closure_def_id),
1671+
tcx.closure_base_def_id(closure_def_id.to_def_id()).assert_local(),
16721672
);
16731673
debug!("apply_requirements: closure_mapping={:?}", closure_mapping);
16741674

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::dataflow::FlowAtLocation;
2222
use crate::dataflow::MaybeInitializedPlaces;
2323
use either::Either;
2424
use rustc::hir;
25-
use rustc::hir::def_id::DefId;
25+
use rustc::hir::def_id::{DefId, LocalDefId};
2626
use rustc::infer::canonical::QueryRegionConstraints;
2727
use rustc::infer::outlives::env::RegionBoundPairs;
2828
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime, NLLRegionVariableOrigin};
@@ -2543,7 +2543,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25432543
// clauses on the struct.
25442544
AggregateKind::Closure(def_id, substs)
25452545
| AggregateKind::Generator(def_id, substs, _) => {
2546-
self.prove_closure_bounds(tcx, *def_id, substs, location)
2546+
self.prove_closure_bounds(tcx, def_id.assert_local(), substs, location)
25472547
}
25482548

25492549
AggregateKind::Array(_) | AggregateKind::Tuple => ty::InstantiatedPredicates::empty(),
@@ -2558,11 +2558,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25582558
fn prove_closure_bounds(
25592559
&mut self,
25602560
tcx: TyCtxt<'tcx>,
2561-
def_id: DefId,
2561+
def_id: LocalDefId,
25622562
substs: SubstsRef<'tcx>,
25632563
location: Location,
25642564
) -> ty::InstantiatedPredicates<'tcx> {
2565-
if let Some(closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements {
2565+
let borrowck_results = tcx.mir_borrowck(def_id.to_def_id());
2566+
if let Some(closure_region_requirements) = borrowck_results.closure_requirements {
25662567
let closure_constraints = QueryRegionConstraints {
25672568
outlives: closure_region_requirements.apply_requirements(tcx, def_id, substs),
25682569

@@ -2621,7 +2622,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26212622
);
26222623
}
26232624

2624-
tcx.predicates_of(def_id).instantiate(tcx, substs)
2625+
tcx.predicates_of(def_id.to_def_id()).instantiate(tcx, substs)
26252626
}
26262627

26272628
fn prove_trait_ref(

src/librustc_mir/borrow_check/nll/universal_regions.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! just returns them for other code to use.
1414
1515
use either::Either;
16-
use rustc::hir::def_id::DefId;
16+
use rustc::hir::def_id::{DefId, LocalDefId};
1717
use rustc::hir::{self, BodyOwnerKind, HirId};
1818
use rustc::infer::{InferCtxt, NLLRegionVariableOrigin};
1919
use rustc::middle::lang_items;
@@ -224,7 +224,7 @@ impl<'tcx> UniversalRegions<'tcx> {
224224
tcx: TyCtxt<'tcx>,
225225
closure_substs: SubstsRef<'tcx>,
226226
expected_num_vars: usize,
227-
closure_base_def_id: DefId,
227+
closure_base_def_id: LocalDefId,
228228
) -> IndexVec<RegionVid, ty::Region<'tcx>> {
229229
let mut region_mapping = IndexVec::with_capacity(expected_num_vars);
230230
region_mapping.push(tcx.lifetimes.re_static);
@@ -322,7 +322,7 @@ impl<'tcx> UniversalRegions<'tcx> {
322322
// tests, and the resulting print-outs include def-ids
323323
// and other things that are not stable across tests!
324324
// So we just include the region-vid. Annoying.
325-
let closure_base_def_id = tcx.closure_base_def_id(def_id);
325+
let closure_base_def_id = tcx.closure_base_def_id(def_id).assert_local();
326326
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
327327
err.note(&format!(
328328
"late-bound region is {:?}",
@@ -340,7 +340,7 @@ impl<'tcx> UniversalRegions<'tcx> {
340340
// FIXME: As above, we'd like to print out the region
341341
// `r` but doing so is not stable across architectures
342342
// and so forth.
343-
let closure_base_def_id = tcx.closure_base_def_id(def_id);
343+
let closure_base_def_id = tcx.closure_base_def_id(def_id).assert_local();
344344
for_each_late_bound_region_defined_on(tcx, closure_base_def_id, |r| {
345345
err.note(&format!(
346346
"late-bound region is {:?}",
@@ -725,7 +725,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
725725
"replace_late_bound_regions_with_nll_infer_vars(mir_def_id={:?})",
726726
mir_def_id
727727
);
728-
let closure_base_def_id = self.tcx.closure_base_def_id(mir_def_id);
728+
let closure_base_def_id = self.tcx.closure_base_def_id(mir_def_id).assert_local();
729729
for_each_late_bound_region_defined_on(self.tcx, closure_base_def_id, |r| {
730730
debug!("replace_late_bound_regions_with_nll_infer_vars: r={:?}", r);
731731
if !indices.indices.contains_key(&r) {
@@ -781,19 +781,19 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
781781
/// invokes `f` with the liberated form of each one.
782782
fn for_each_late_bound_region_defined_on<'tcx>(
783783
tcx: TyCtxt<'tcx>,
784-
fn_def_id: DefId,
784+
fn_def_id: LocalDefId,
785785
mut f: impl FnMut(ty::Region<'tcx>),
786786
) {
787-
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id.assert_local()) {
787+
if let Some(late_bounds) = tcx.is_late_bound_map(fn_def_id) {
788788
for late_bound in late_bounds.iter() {
789789
let hir_id = HirId {
790-
owner: fn_def_id.assert_local(),
790+
owner: fn_def_id,
791791
local_id: *late_bound,
792792
};
793793
let name = tcx.hir().name(hir_id);
794794
let region_def_id = tcx.hir().local_def_id(hir_id);
795795
let liberated_region = tcx.mk_region(ty::ReFree(ty::FreeRegion {
796-
scope: fn_def_id,
796+
scope: fn_def_id.to_def_id(),
797797
bound_region: ty::BoundRegion::BrNamed(region_def_id, name),
798798
}));
799799
f(liberated_region);

src/librustc_mir/build/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ where
548548
let span = tcx_hir.span(fn_id);
549549

550550
let hir_tables = hir.tables();
551-
let fn_def_id = tcx_hir.local_def_id(fn_id);
551+
let fn_def_id = tcx_hir.local_def_id(fn_id).assert_local();
552552

553553
// Gather the upvars of a closure, if any.
554554
let mut upvar_mutbls = vec![];
@@ -613,7 +613,7 @@ where
613613
let source_info = builder.source_info(span);
614614
let call_site_s = (call_site_scope, source_info);
615615
unpack!(block = builder.in_scope(call_site_s, LintLevel::Inherited, |builder| {
616-
if should_abort_on_panic(tcx, fn_def_id, abi) {
616+
if should_abort_on_panic(tcx, fn_def_id.to_def_id(), abi) {
617617
builder.schedule_abort();
618618
}
619619

@@ -653,7 +653,7 @@ where
653653
spread_arg = Some(Local::new(arguments.len()));
654654
}
655655
info!("fn_id {:?} has attrs {:?}", fn_def_id,
656-
tcx.get_attrs(fn_def_id));
656+
tcx.get_attrs(fn_def_id.to_def_id()));
657657

658658
let mut body = builder.finish(yield_ty);
659659
body.spread_arg = spread_arg;

src/librustc_mir/hair/cx/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ fn convert_var(
983983
let closure_def_id = cx.body_owner;
984984
let upvar_id = ty::UpvarId {
985985
var_path: ty::UpvarPath {hir_id: var_hir_id},
986-
closure_expr_id: closure_def_id.assert_local(),
986+
closure_expr_id: closure_def_id,
987987
};
988988
let var_ty = cx.tables().node_type(var_hir_id);
989989

@@ -996,13 +996,13 @@ fn convert_var(
996996
// signature will be &self or &mut self and hence will
997997
// have a bound region with number 0
998998
let region = ty::ReFree(ty::FreeRegion {
999-
scope: closure_def_id,
999+
scope: closure_def_id.to_def_id(),
10001000
bound_region: ty::BoundRegion::BrAnon(0),
10011001
});
10021002
let region = cx.tcx.mk_region(region);
10031003

10041004
let self_expr = if let ty::Closure(_, closure_substs) = closure_ty.kind {
1005-
match cx.infcx.closure_kind(closure_def_id, closure_substs).unwrap() {
1005+
match cx.infcx.closure_kind(closure_def_id.to_def_id(), closure_substs).unwrap() {
10061006
ty::ClosureKind::Fn => {
10071007
let ref_closure_ty = cx.tcx.mk_ref(region,
10081008
ty::TypeAndMut {

0 commit comments

Comments
 (0)