// 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;
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>,
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)) => {
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| {
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.
});
}
- 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),
})