Replace type_param_to_index with param_def_id_to_index
This commit is contained in:
parent
7b45a892a4
commit
df1c256a2b
5 changed files with 19 additions and 14 deletions
|
@ -740,7 +740,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
|
|||
|
||||
// Reverse map to each `TypeParamDef`'s `index` field, from
|
||||
// `def_id.index` (`def_id.krate` is the same as the item's).
|
||||
type_param_to_index: _, // Don't hash this
|
||||
param_def_id_to_index: _, // Don't hash this
|
||||
has_self,
|
||||
has_late_bound_regions,
|
||||
} = *self;
|
||||
|
|
|
@ -796,7 +796,7 @@ pub struct Generics {
|
|||
pub params: Vec<GenericParamDef>,
|
||||
|
||||
/// Reverse map to each `TypeParamDef`'s `index` field
|
||||
pub type_param_to_index: FxHashMap<DefId, u32>,
|
||||
pub param_def_id_to_index: FxHashMap<DefId, u32>,
|
||||
|
||||
pub has_self: bool,
|
||||
pub has_late_bound_regions: Option<Span>,
|
||||
|
|
|
@ -985,7 +985,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
let item_id = tcx.hir.get_parent_node(node_id);
|
||||
let item_def_id = tcx.hir.local_def_id(item_id);
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id)];
|
||||
let index = generics.param_def_id_to_index[&tcx.hir.local_def_id(node_id)];
|
||||
tcx.mk_param(index, tcx.hir.name(node_id).as_interned_str())
|
||||
}
|
||||
Def::SelfTy(_, Some(def_id)) => {
|
||||
|
|
|
@ -1716,7 +1716,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
|
|||
let item_id = tcx.hir.ty_param_owner(node_id);
|
||||
let item_def_id = tcx.hir.local_def_id(item_id);
|
||||
let generics = tcx.generics_of(item_def_id);
|
||||
let index = generics.type_param_to_index[&def_id];
|
||||
let index = generics.param_def_id_to_index[&def_id];
|
||||
ty::GenericPredicates {
|
||||
parent: None,
|
||||
predicates: self.param_env.caller_bounds.iter().filter(|predicate| {
|
||||
|
|
|
@ -243,7 +243,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
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 index = generics.type_param_to_index[&def_id];
|
||||
let index = generics.param_def_id_to_index[&def_id];
|
||||
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id).as_interned_str());
|
||||
|
||||
// Don't look for bounds where the type parameter isn't in scope.
|
||||
|
@ -966,23 +966,28 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
});
|
||||
}
|
||||
|
||||
let type_param_to_index = opt_self.iter()
|
||||
.chain(types.iter())
|
||||
.map(|ty| (ty.def_id, ty.index))
|
||||
.collect();
|
||||
|
||||
let opt_self = opt_self.into_iter().map(|ty| ty::GenericParamDef::Type(ty));
|
||||
let lifetimes = regions.into_iter().map(|lt| ty::GenericParamDef::Lifetime(lt));
|
||||
let types = types.into_iter().map(|ty| ty::GenericParamDef::Type(ty));
|
||||
let params = opt_self.chain(lifetimes)
|
||||
.chain(types)
|
||||
.collect();
|
||||
let params: Vec<_> = opt_self.chain(lifetimes)
|
||||
.chain(types)
|
||||
.collect();
|
||||
|
||||
let param_def_id_to_index =
|
||||
params.iter()
|
||||
.map(|param| {
|
||||
match param {
|
||||
ty::GenericParamDef::Lifetime(lt) => (lt.def_id, lt.index),
|
||||
ty::GenericParamDef::Type(ty) => (ty.def_id, ty.index),
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
tcx.alloc_generics(ty::Generics {
|
||||
parent: parent_def_id,
|
||||
parent_count,
|
||||
params,
|
||||
type_param_to_index,
|
||||
param_def_id_to_index,
|
||||
has_self: has_self || parent_has_self,
|
||||
has_late_bound_regions: has_late_bound_regions(tcx, node),
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue