Compute ty_param_owner
using DefIdTree.
This commit is contained in:
parent
dd38eea722
commit
b5dfa6a78d
@ -1,5 +1,5 @@
|
||||
use crate::hir::{ModuleItems, Owner};
|
||||
use crate::ty::TyCtxt;
|
||||
use crate::ty::{DefIdTree, TyCtxt};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
@ -545,13 +545,12 @@ pub fn par_body_owners<F: Fn(LocalDefId) + Sync + Send>(self, f: F) {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn ty_param_owner(self, id: HirId) -> LocalDefId {
|
||||
match self.get(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)),
|
||||
pub fn ty_param_owner(self, def_id: LocalDefId) -> LocalDefId {
|
||||
let def_kind = self.tcx.def_kind(def_id);
|
||||
match def_kind {
|
||||
DefKind::Trait | DefKind::TraitAlias => def_id,
|
||||
DefKind::TyParam | DefKind::ConstParam => self.tcx.local_parent(def_id).unwrap(),
|
||||
_ => bug!("ty_param_owner: {:?} is a {:?} not a type parameter", def_id, def_kind),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2265,11 +2265,11 @@ pub fn res_to_ty(
|
||||
assert_eq!(opt_self_ty, None);
|
||||
self.prohibit_generics(path.segments);
|
||||
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let item_id = tcx.hir().get_parent_node(hir_id);
|
||||
let item_def_id = tcx.hir().local_def_id(item_id);
|
||||
let def_id = def_id.expect_local();
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
|
||||
let item_def_id = tcx.hir().ty_param_owner(def_id);
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.param_def_id_to_index[&def_id];
|
||||
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
|
||||
tcx.mk_ty_param(index, tcx.hir().name(hir_id))
|
||||
}
|
||||
Res::SelfTy { trait_: Some(_), alias_to: None } => {
|
||||
|
@ -184,8 +184,7 @@ fn get_type_parameter_bounds(
|
||||
_: Ident,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
|
||||
let item_def_id = tcx.hir().ty_param_owner(hir_id);
|
||||
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.param_def_id_to_index[&def_id];
|
||||
ty::GenericPredicates {
|
||||
|
@ -558,7 +558,7 @@ fn type_param_predicates(
|
||||
// `where T: Foo`.
|
||||
|
||||
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 = tcx.hir().ty_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));
|
||||
|
Loading…
Reference in New Issue
Block a user