Skip to content

Commit

Permalink
Make ty_param_owner return a LocalDefId.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jan 15, 2022
1 parent 79afe99 commit ebcc847
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 5 additions & 3 deletions compiler/rustc_middle/src/hir/map/mod.rs
Expand Up @@ -546,10 +546,12 @@ impl<'hir> Map<'hir> {
});
}

pub fn ty_param_owner(&self, id: HirId) -> HirId {
pub fn ty_param_owner(&self, id: HirId) -> LocalDefId {
match self.get(id) {
Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => id,
Node::GenericParam(_) => self.get_parent_node(id),
Node::Item(&Item { kind: ItemKind::Trait(..) | ItemKind::TraitAlias(..), .. }) => {
id.expect_owner()
}
Node::GenericParam(_) => self.get_parent_item(id),
_ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id)),
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_typeck/src/check/fn_ctxt/mod.rs
Expand Up @@ -188,8 +188,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
) -> ty::GenericPredicates<'tcx> {
let tcx = self.tcx;
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let item_id = tcx.hir().ty_param_owner(hir_id);
let item_def_id = tcx.hir().local_def_id(item_id);
let item_def_id = tcx.hir().ty_param_owner(hir_id);
let generics = tcx.generics_of(item_def_id);
let index = generics.param_def_id_to_index[&def_id];
ty::GenericPredicates {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_typeck/src/collect.rs
Expand Up @@ -569,13 +569,12 @@ fn type_param_predicates(

let param_id = tcx.hir().local_def_id_to_hir_id(def_id);
let param_owner = tcx.hir().ty_param_owner(param_id);
let param_owner_def_id = tcx.hir().local_def_id(param_owner);
let generics = tcx.generics_of(param_owner_def_id);
let generics = tcx.generics_of(param_owner);
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
let ty = tcx.mk_ty_param(index, tcx.hir().ty_param_name(param_id));

// Don't look for bounds where the type parameter isn't in scope.
let parent = if item_def_id == param_owner_def_id.to_def_id() {
let parent = if item_def_id == param_owner.to_def_id() {
None
} else {
tcx.generics_of(item_def_id).parent
Expand Down

0 comments on commit ebcc847

Please sign in to comment.