TypeIdHasher: Let projections be hashed implicitly by the visitor.

This commit is contained in:
Michael Woerister 2016-09-13 15:02:17 -04:00
parent 75a0dd0fca
commit 869d14447a
4 changed files with 19 additions and 11 deletions

View file

@ -453,17 +453,6 @@ impl<'a, 'gcx, 'tcx> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx> {
// Hash region and builtin bounds.
data.region_bound.visit_with(self);
self.hash(data.builtin_bounds);
// Only projection bounds are left, hash them.
self.hash(data.projection_bounds.len());
for bound in &data.projection_bounds {
self.def_id(bound.0.trait_ref.def_id);
self.hash(bound.0.item_name);
bound.visit_with(self);
}
// Bypass super_visit_with, we've visited everything.
return false;
}
TyTuple(tys) => {
self.hash(tys.len());

View file

@ -22,6 +22,8 @@ pub type F = Option<isize>;
pub type G = usize;
pub type H = &'static str;
pub type I = Box<Fn()>;
pub type I32Iterator = Iterator<Item=i32>;
pub type U32Iterator = Iterator<Item=u32>;
pub fn id_A() -> TypeId { TypeId::of::<A>() }
pub fn id_B() -> TypeId { TypeId::of::<B>() }
@ -34,3 +36,6 @@ pub fn id_H() -> TypeId { TypeId::of::<H>() }
pub fn id_I() -> TypeId { TypeId::of::<I>() }
pub fn foo<T: Any>() -> TypeId { TypeId::of::<T>() }
pub fn id_i32_iterator() -> TypeId { TypeId::of::<I32Iterator>() }
pub fn id_u32_iterator() -> TypeId { TypeId::of::<U32Iterator>() }

View file

@ -22,6 +22,8 @@ pub type F = Option<isize>;
pub type G = usize;
pub type H = &'static str;
pub type I = Box<Fn()>;
pub type I32Iterator = Iterator<Item=i32>;
pub type U32Iterator = Iterator<Item=u32>;
pub fn id_A() -> TypeId { TypeId::of::<A>() }
pub fn id_B() -> TypeId { TypeId::of::<B>() }
@ -34,3 +36,6 @@ pub fn id_H() -> TypeId { TypeId::of::<H>() }
pub fn id_I() -> TypeId { TypeId::of::<I>() }
pub fn foo<T: Any>() -> TypeId { TypeId::of::<T>() }
pub fn id_i32_iterator() -> TypeId { TypeId::of::<I32Iterator>() }
pub fn id_u32_iterator() -> TypeId { TypeId::of::<U32Iterator>() }

View file

@ -78,4 +78,13 @@ pub fn main() {
b.hash(&mut s2);
assert_eq!(s1.finish(), s2.finish());
// Check projections
assert_eq!(TypeId::of::<other1::I32Iterator>(), other1::id_i32_iterator());
assert_eq!(TypeId::of::<other1::U32Iterator>(), other1::id_u32_iterator());
assert_eq!(other1::id_i32_iterator(), other2::id_i32_iterator());
assert_eq!(other1::id_u32_iterator(), other2::id_u32_iterator());
assert!(other1::id_i32_iterator() != other1::id_u32_iterator());
assert!(TypeId::of::<other1::I32Iterator>() != TypeId::of::<other1::U32Iterator>());
}