Skip to content

Commit

Permalink
TypeIdHasher: Let projections be hashed implicitly by the visitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Sep 13, 2016
1 parent 75a0dd0 commit 869d144
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/librustc/ty/util.rs
Expand Up @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions src/test/run-pass/auxiliary/typeid-intrinsic-aux1.rs
Expand Up @@ -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>() }
Expand All @@ -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>() }
5 changes: 5 additions & 0 deletions src/test/run-pass/auxiliary/typeid-intrinsic-aux2.rs
Expand Up @@ -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>() }
Expand All @@ -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>() }
9 changes: 9 additions & 0 deletions src/test/run-pass/typeid-intrinsic.rs
Expand Up @@ -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>());
}

0 comments on commit 869d144

Please sign in to comment.