Skip to content

Commit 169c399

Browse files
committed
Use LocalDefId in typeck_tables_of and used_trait_imports queries
1 parent a58b1ed commit 169c399

File tree

18 files changed

+79
-58
lines changed

18 files changed

+79
-58
lines changed

src/librustc_middle/query/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,13 @@ rustc_queries! {
459459
desc { "type-checking all item bodies" }
460460
}
461461

462-
query typeck_tables_of(key: DefId) -> &'tcx ty::TypeckTables<'tcx> {
463-
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key) }
464-
cache_on_disk_if { key.is_local() }
462+
query typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> {
463+
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
464+
cache_on_disk_if { true }
465465
}
466-
query diagnostic_only_typeck_tables_of(key: DefId) -> &'tcx ty::TypeckTables<'tcx> {
467-
cache_on_disk_if { key.is_local() }
466+
query diagnostic_only_typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> {
467+
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) }
468+
cache_on_disk_if { true }
468469
load_cached(tcx, id) {
469470
let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
470471
.queries.on_disk_cache
@@ -476,8 +477,9 @@ rustc_queries! {
476477
}
477478

478479
Other {
479-
query used_trait_imports(key: DefId) -> &'tcx DefIdSet {
480-
cache_on_disk_if { key.is_local() }
480+
query used_trait_imports(key: LocalDefId) -> &'tcx DefIdSet {
481+
desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
482+
cache_on_disk_if { true }
481483
}
482484
}
483485

src/librustc_middle/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,7 @@ pub enum ImplOverlapKind {
26372637

26382638
impl<'tcx> TyCtxt<'tcx> {
26392639
pub fn body_tables(self, body: hir::BodyId) -> &'tcx TypeckTables<'tcx> {
2640-
self.typeck_tables_of(self.hir().body_owner_def_id(body).to_def_id())
2640+
self.typeck_tables_of(self.hir().body_owner_def_id(body))
26412641
}
26422642

26432643
/// Returns an iterator of the `DefId`s for all body-owners in this

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
191191
.ty;
192192
let needs_note = match ty.kind {
193193
ty::Closure(id, _) => {
194-
let tables = self.infcx.tcx.typeck_tables_of(id);
194+
let tables = self.infcx.tcx.typeck_tables_of(id.expect_local());
195195
let hir_id = self.infcx.tcx.hir().as_local_hir_id(id.expect_local());
196196

197197
tables.closure_kind_origins().get(hir_id).is_none()
@@ -880,7 +880,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
880880
match &self
881881
.infcx
882882
.tcx
883-
.typeck_tables_of(self.mir_def_id)
883+
.typeck_tables_of(def_id)
884884
.node_type(fn_hir_id)
885885
.kind
886886
{

src/librustc_mir/borrow_check/diagnostics/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
9797

9898
debug!("add_moved_or_invoked_closure_note: closure={:?}", closure);
9999
if let ty::Closure(did, _) = self.body.local_decls[closure].ty.kind {
100-
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did.expect_local());
100+
let did = did.expect_local();
101+
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did);
101102

102103
if let Some((span, name)) =
103104
self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id)
@@ -119,7 +120,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
119120
// Check if we are just moving a closure after it has been invoked.
120121
if let Some(target) = target {
121122
if let ty::Closure(did, _) = self.body.local_decls[target].ty.kind {
122-
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did.expect_local());
123+
let did = did.expect_local();
124+
let hir_id = self.infcx.tcx.hir().as_local_hir_id(did);
123125

124126
if let Some((span, name)) =
125127
self.infcx.tcx.typeck_tables_of(did).closure_kind_origins().get(hir_id)

src/librustc_mir/borrow_check/type_check/input_output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3636
if !self.tcx().is_closure(self.mir_def_id) {
3737
user_provided_sig = None;
3838
} else {
39-
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id);
39+
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id.expect_local());
4040
user_provided_sig = match typeck_tables.user_provided_sigs.get(&self.mir_def_id) {
4141
None => None,
4242
Some(user_provided_poly_sig) => {

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
12321232
let tcx = infcx.tcx;
12331233
let param_env = self.param_env;
12341234
let body = self.body;
1235-
let concrete_opaque_types = &tcx.typeck_tables_of(anon_owner_def_id).concrete_opaque_types;
1235+
let concrete_opaque_types =
1236+
&tcx.typeck_tables_of(anon_owner_def_id.expect_local()).concrete_opaque_types;
12361237
let mut opaque_type_values = Vec::new();
12371238

12381239
debug!("eq_opaque_type_and_type: mir_def_id={:?}", self.mir_def_id);

src/librustc_mir/borrow_check/universal_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
498498
let defining_ty = if self.mir_def_id == closure_base_def_id {
499499
tcx.type_of(closure_base_def_id)
500500
} else {
501-
let tables = tcx.typeck_tables_of(self.mir_def_id);
501+
let tables = tcx.typeck_tables_of(self.mir_def_id.expect_local());
502502
tables.node_type(self.mir_hir_id)
503503
};
504504

src/librustc_mir/const_eval/eval_queries.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,11 @@ pub fn const_eval_raw_provider<'tcx>(
289289
let cid = key.value;
290290
let def_id = cid.instance.def.def_id();
291291

292-
if def_id.is_local() && tcx.has_typeck_tables(def_id) {
293-
if let Some(error_reported) = tcx.typeck_tables_of(def_id).tainted_by_errors {
294-
return Err(ErrorHandled::Reported(error_reported));
292+
if let Some(def_id) = def_id.as_local() {
293+
if tcx.has_typeck_tables(def_id) {
294+
if let Some(error_reported) = tcx.typeck_tables_of(def_id).tainted_by_errors {
295+
return Err(ErrorHandled::Reported(error_reported));
296+
}
295297
}
296298
}
297299

src/librustc_mir/interpret/eval_context.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
402402
) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
403403
// do not continue if typeck errors occurred (can only occur in local crate)
404404
let did = instance.def_id();
405-
if did.is_local() && self.tcx.has_typeck_tables(did) {
406-
if let Some(error_reported) = self.tcx.typeck_tables_of(did).tainted_by_errors {
407-
throw_inval!(TypeckError(error_reported))
405+
if let Some(did) = did.as_local() {
406+
if self.tcx.has_typeck_tables(did) {
407+
if let Some(error_reported) = self.tcx.typeck_tables_of(did).tainted_by_errors {
408+
throw_inval!(TypeckError(error_reported))
409+
}
408410
}
409411
}
410412
trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);

src/librustc_mir/interpret/validity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
199199
// generators and closures.
200200
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
201201
let mut name = None;
202-
if def_id.is_local() {
202+
if let Some(def_id) = def_id.as_local() {
203203
let tables = self.ecx.tcx.typeck_tables_of(def_id);
204-
if let Some(upvars) = tables.upvar_list.get(&def_id) {
204+
if let Some(upvars) = tables.upvar_list.get(&def_id.to_def_id()) {
205205
// Sometimes the index is beyond the number of upvars (seen
206206
// for a generator).
207207
if let Some((&var_hir_id, _)) = upvars.get_index(field) {

0 commit comments

Comments
 (0)