use hir::def_id::{DefId, LOCAL_CRATE};
use hir::map::DefPathData;
use infer::InferCtxt;
-use hir::map as hir_map;
+// use hir::map as hir_map;
use traits::{self, Reveal};
use ty::{self, Ty, TyCtxt, TypeAndMut, TypeFlags, TypeFoldable};
use ty::ParameterEnvironment;
}
def_id
}
+
+ /// Given the def-id of some item that has no type parameters, make
+ /// a suitable "empty substs" for it.
+ pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> &'tcx ty::Substs<'tcx> {
+ ty::Substs::for_item(self, item_def_id,
+ |_, _| self.mk_region(ty::ReErased),
+ |_, _| {
+ bug!("empty_substs_for_def_id: {:?} has type parameters", item_def_id)
+ })
+ }
}
pub struct TypeIdHasher<'a, 'gcx: 'a+'tcx, 'tcx: 'a, W> {
fn def_id(&mut self, did: DefId) {
// Hash the DefPath corresponding to the DefId, which is independent
- // of compiler internal state.
- let path = self.tcx.def_path(did);
- self.def_path(&path)
- }
-
- pub fn def_path(&mut self, def_path: &hir_map::DefPath) {
- def_path.deterministic_hash_to(self.tcx, &mut self.state);
+ // of compiler internal state. We already have a stable hash value of
+ // all DefPaths available via tcx.def_path_hash(), so we just feed that
+ // into the hasher.
+ let hash = self.tcx.def_path_hash(did);
+ self.hash(hash);
}
}
}
fn visit_region(&mut self, r: &'tcx ty::Region) -> bool {
+ self.hash_discriminant_u8(r);
match *r {
- ty::ReErased => {
- self.hash::<u32>(0);
+ ty::ReErased |
+ ty::ReStatic |
+ ty::ReEmpty => {
+ // No variant fields to hash for these ...
}
ty::ReLateBound(db, ty::BrAnon(i)) => {
- assert!(db.depth > 0);
- self.hash::<u32>(db.depth);
+ self.hash(db.depth);
self.hash(i);
}
- ty::ReStatic |
- ty::ReEmpty |
- ty::ReEarlyBound(..) |
+ ty::ReEarlyBound(ty::EarlyBoundRegion { index, name }) => {
+ self.hash(index);
+ self.hash(name.as_str());
+ }
ty::ReLateBound(..) |
ty::ReFree(..) |
ty::ReScope(..) |