Skip to content

Commit f27cec9

Browse files
committed
Use LocalDefId for type_param_predicates query
1 parent d9e286b commit f27cec9

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/librustc_middle/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ rustc_queries! {
275275

276276
/// To avoid cycles within the predicates of a single item we compute
277277
/// per-type-parameter predicates for resolving `T::AssocTy`.
278-
query type_param_predicates(key: (DefId, DefId)) -> ty::GenericPredicates<'tcx> {
278+
query type_param_predicates(key: (DefId, LocalDefId)) -> ty::GenericPredicates<'tcx> {
279279
desc { |tcx| "computing the bounds for type parameter `{}`", {
280-
let id = tcx.hir().as_local_hir_id(key.1.expect_local());
280+
let id = tcx.hir().as_local_hir_id(key.1);
281281
tcx.hir().ty_param_name(id)
282282
}}
283283
}

src/librustc_middle/ty/query/keys.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ impl Key for (DefId, DefId) {
117117
}
118118
}
119119

120+
impl Key for (DefId, LocalDefId) {
121+
type CacheSelector = DefaultCacheSelector;
122+
123+
fn query_crate(&self) -> CrateNum {
124+
self.0.krate
125+
}
126+
fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
127+
self.1.default_span(tcx)
128+
}
129+
}
130+
120131
impl Key for (CrateNum, DefId) {
121132
type CacheSelector = DefaultCacheSelector;
122133

src/librustc_typeck/collect.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
295295
}
296296

297297
fn get_type_parameter_bounds(&self, span: Span, def_id: DefId) -> ty::GenericPredicates<'tcx> {
298-
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id))
298+
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id.expect_local()))
299299
}
300300

301301
fn re_infer(&self, _: Option<&ty::GenericParamDef>, _: Span) -> Option<ty::Region<'tcx>> {
@@ -478,19 +478,19 @@ fn get_new_lifetime_name<'tcx>(
478478
/// `X: Foo` where `X` is the type parameter `def_id`.
479479
fn type_param_predicates(
480480
tcx: TyCtxt<'_>,
481-
(item_def_id, def_id): (DefId, DefId),
481+
(item_def_id, def_id): (DefId, LocalDefId),
482482
) -> ty::GenericPredicates<'_> {
483483
use rustc_hir::*;
484484

485485
// In the AST, bounds can derive from two places. Either
486486
// written inline like `<T: Foo>` or in a where-clause like
487487
// `where T: Foo`.
488488

489-
let param_id = tcx.hir().as_local_hir_id(def_id.expect_local());
489+
let param_id = tcx.hir().as_local_hir_id(def_id);
490490
let param_owner = tcx.hir().ty_param_owner(param_id);
491491
let param_owner_def_id = tcx.hir().local_def_id(param_owner);
492492
let generics = tcx.generics_of(param_owner_def_id);
493-
let index = generics.param_def_id_to_index[&def_id];
493+
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
494494
let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(param_id));
495495

496496
// Don't look for bounds where the type parameter isn't in scope.
@@ -503,7 +503,7 @@ fn type_param_predicates(
503503
let mut result = parent
504504
.map(|parent| {
505505
let icx = ItemCtxt::new(tcx, parent);
506-
icx.get_type_parameter_bounds(DUMMY_SP, def_id)
506+
icx.get_type_parameter_bounds(DUMMY_SP, def_id.to_def_id())
507507
})
508508
.unwrap_or_default();
509509
let mut extend = None;

0 commit comments

Comments
 (0)