Skip to content

Commit a5d7aae

Browse files
Make ty::Generics::type_param_to_index use DefId instead of DefIndex as key.
1 parent a084cd0 commit a5d7aae

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

src/librustc/ty/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::fold::TypeFoldable;
1717

1818
use hir::{map as hir_map, FreevarMap, TraitMap};
1919
use hir::def::{Def, CtorKind, ExportMap};
20-
use hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
20+
use hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
2121
use hir::map::DefPathData;
2222
use hir::svh::Svh;
2323
use ich::Fingerprint;
@@ -39,7 +39,6 @@ use util::nodemap::{NodeSet, DefIdMap, FxHashMap, FxHashSet};
3939

4040
use serialize::{self, Encodable, Encoder};
4141
use std::cell::RefCell;
42-
use std::collections::BTreeMap;
4342
use std::cmp;
4443
use std::fmt;
4544
use std::hash::{Hash, Hasher};
@@ -758,9 +757,8 @@ pub struct Generics {
758757
pub regions: Vec<RegionParameterDef>,
759758
pub types: Vec<TypeParameterDef>,
760759

761-
/// Reverse map to each `TypeParameterDef`'s `index` field, from
762-
/// `def_id.index` (`def_id.krate` is the same as the item's).
763-
pub type_param_to_index: BTreeMap<DefIndex, u32>,
760+
/// Reverse map to each `TypeParameterDef`'s `index` field
761+
pub type_param_to_index: FxHashMap<DefId, u32>,
764762

765763
pub has_self: bool,
766764
pub has_late_bound_regions: Option<Span>,

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
979979
let item_id = tcx.hir.get_parent_node(node_id);
980980
let item_def_id = tcx.hir.local_def_id(item_id);
981981
let generics = tcx.generics_of(item_def_id);
982-
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id).index];
982+
let index = generics.type_param_to_index[&tcx.hir.local_def_id(node_id)];
983983
tcx.mk_param(index, tcx.hir.name(node_id))
984984
}
985985
Def::SelfTy(_, Some(def_id)) => {

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx> for FnCtxt<'a, 'gcx, 'tcx> {
16291629
let item_id = tcx.hir.ty_param_owner(node_id);
16301630
let item_def_id = tcx.hir.local_def_id(item_id);
16311631
let generics = tcx.generics_of(item_def_id);
1632-
let index = generics.type_param_to_index[&def_id.index];
1632+
let index = generics.type_param_to_index[&def_id];
16331633
ty::GenericPredicates {
16341634
parent: None,
16351635
predicates: self.param_env.caller_bounds.iter().filter(|predicate| {

src/librustc_typeck/collect.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ use util::nodemap::FxHashMap;
4040

4141
use rustc_const_math::ConstInt;
4242

43-
use std::collections::BTreeMap;
44-
4543
use syntax::{abi, ast};
4644
use syntax::codemap::Spanned;
4745
use syntax::symbol::{Symbol, keywords};
@@ -240,7 +238,7 @@ fn type_param_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
240238
let param_owner = tcx.hir.ty_param_owner(param_id);
241239
let param_owner_def_id = tcx.hir.local_def_id(param_owner);
242240
let generics = tcx.generics_of(param_owner_def_id);
243-
let index = generics.type_param_to_index[&def_id.index];
241+
let index = generics.type_param_to_index[&def_id];
244242
let ty = tcx.mk_param(index, tcx.hir.ty_param_name(param_id));
245243

246244
// 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>,
10241022
});
10251023
}
10261024

1027-
let mut type_param_to_index = BTreeMap::new();
1028-
for param in &types {
1029-
type_param_to_index.insert(param.def_id.index, param.index);
1030-
}
1025+
let type_param_to_index = types.iter()
1026+
.map(|param| (param.def_id, param.index))
1027+
.collect();
10311028

10321029
tcx.alloc_generics(ty::Generics {
10331030
parent: parent_def_id,

0 commit comments

Comments
 (0)