From df1c256a2b1e7c68f343f40a870fa762a63a0a05 Mon Sep 17 00:00:00 2001 From: varkor Date: Wed, 18 Apr 2018 12:45:13 +0100 Subject: [PATCH] Replace type_param_to_index with param_def_id_to_index --- src/librustc/ich/impls_ty.rs | 2 +- src/librustc/ty/mod.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/collect.rs | 25 +++++++++++++++---------- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index d0427ef4be22..fc0a9ac9d18f 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -740,7 +740,7 @@ impl<'a> HashStable> 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; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 0cbee56487ff..35a44bcf4030 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -796,7 +796,7 @@ pub struct Generics { pub params: Vec, /// Reverse map to each `TypeParamDef`'s `index` field - pub type_param_to_index: FxHashMap, + pub param_def_id_to_index: FxHashMap, pub has_self: bool, pub has_late_bound_regions: Option, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 11003a49316e..2c9995b25a1b 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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)) => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3df584040ad3..0726650b0548 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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| { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 1a8d4392f645..452b76e1b702 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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), })