]> git.lizzy.rs Git - rust.git/commitdiff
Make ty::Generics::type_param_to_index use DefId instead of DefIndex as key.
authorMichael Woerister <michaelwoerister@posteo>
Wed, 17 Jan 2018 15:23:50 +0000 (16:23 +0100)
committerMichael Woerister <michaelwoerister@posteo>
Tue, 23 Jan 2018 09:44:52 +0000 (10:44 +0100)
src/librustc/ty/mod.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/collect.rs

index 123432074761ba15197aec10b7d6e6678a4e3cec..2c3454e7b5c7bb61cdd5b48daaa2471686758885 100644 (file)
@@ -17,7 +17,7 @@
 
 use hir::{map as hir_map, FreevarMap, TraitMap};
 use hir::def::{Def, CtorKind, ExportMap};
-use hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
+use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
 use hir::map::DefPathData;
 use hir::svh::Svh;
 use ich::Fingerprint;
@@ -39,7 +39,6 @@
 
 use serialize::{self, Encodable, Encoder};
 use std::cell::RefCell;
-use std::collections::BTreeMap;
 use std::cmp;
 use std::fmt;
 use std::hash::{Hash, Hasher};
@@ -758,9 +757,8 @@ pub struct Generics {
     pub regions: Vec<RegionParameterDef>,
     pub types: Vec<TypeParameterDef>,
 
-    /// Reverse map to each `TypeParameterDef`'s `index` field, from
-    /// `def_id.index` (`def_id.krate` is the same as the item's).
-    pub type_param_to_index: BTreeMap<DefIndex, u32>,
+    /// Reverse map to each `TypeParameterDef`'s `index` field
+    pub type_param_to_index: FxHashMap<DefId, u32>,
 
     pub has_self: bool,
     pub has_late_bound_regions: Option<Span>,
index 4616b4cf80c97c676ea15dba22786b000f47fbf1..42bc3a25a8d3f729b349e9c087776e5b09e30dcd 100644 (file)
@@ -979,7 +979,7 @@ pub fn def_to_ty(&self,
                 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).index];
+                let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id)];
                 tcx.mk_param(index, tcx.hir.name(node_id))
             }
             Def::SelfTy(_, Some(def_id)) => {
index cb8ce8d5ac331296e971ac3f02bef1cbf36d5331..6702ac2354d79954143401fd4cf91989248a9ca2 100644 (file)
@@ -1629,7 +1629,7 @@ fn get_type_parameter_bounds(&self, _: Span, def_id: DefId)
         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.index];
+        let index = generics.type_param_to_index[&def_id];
         ty::GenericPredicates {
             parent: None,
             predicates: self.param_env.caller_bounds.iter().filter(|predicate| {
index 5485045b7043897f459e02445b8152abde6a1096..71ffb57ab48c75f2383489f608162af1bfa6193e 100644 (file)
@@ -40,8 +40,6 @@
 
 use rustc_const_math::ConstInt;
 
-use std::collections::BTreeMap;
-
 use syntax::{abi, ast};
 use syntax::codemap::Spanned;
 use syntax::symbol::{Symbol, keywords};
@@ -240,7 +238,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.index];
+    let index = generics.type_param_to_index[&def_id];
     let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id));
 
     // Don't look for bounds where the type parameter isn't in scope.
@@ -1024,10 +1022,9 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         });
     }
 
-    let mut type_param_to_index = BTreeMap::new();
-    for param in &types {
-        type_param_to_index.insert(param.def_id.index, param.index);
-    }
+    let type_param_to_index = types.iter()
+                                   .map(|param| (param.def_id, param.index))
+                                   .collect();
 
     tcx.alloc_generics(ty::Generics {
         parent: parent_def_id,