rustc: allow less and handle fn pointers in the type hashing algorithm.
This commit is contained in:
parent
ade79d7609
commit
a2726f4a54
3 changed files with 15 additions and 6 deletions
|
@ -436,17 +436,18 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tc
|
||||||
TyInt(i) => self.hash(i),
|
TyInt(i) => self.hash(i),
|
||||||
TyUint(u) => self.hash(u),
|
TyUint(u) => self.hash(u),
|
||||||
TyFloat(f) => self.hash(f),
|
TyFloat(f) => self.hash(f),
|
||||||
TyAdt(d, _) => self.def_id(d.did),
|
|
||||||
TyArray(_, n) => self.hash(n),
|
TyArray(_, n) => self.hash(n),
|
||||||
TyRawPtr(m) |
|
TyRawPtr(m) |
|
||||||
TyRef(_, m) => self.hash(m.mutbl),
|
TyRef(_, m) => self.hash(m.mutbl),
|
||||||
TyClosure(def_id, _) |
|
TyClosure(def_id, _) |
|
||||||
TyAnon(def_id, _) |
|
TyAnon(def_id, _) |
|
||||||
TyFnDef(def_id, ..) => self.def_id(def_id),
|
TyFnDef(def_id, ..) => self.def_id(def_id),
|
||||||
|
TyAdt(d, _) => self.def_id(d.did),
|
||||||
TyFnPtr(f) => {
|
TyFnPtr(f) => {
|
||||||
self.hash(f.unsafety);
|
self.hash(f.unsafety);
|
||||||
self.hash(f.abi);
|
self.hash(f.abi);
|
||||||
self.hash(f.sig.variadic());
|
self.hash(f.sig.variadic());
|
||||||
|
self.hash(f.sig.inputs().skip_binder().len());
|
||||||
}
|
}
|
||||||
TyTrait(ref data) => {
|
TyTrait(ref data) => {
|
||||||
self.def_id(data.principal.def_id());
|
self.def_id(data.principal.def_id());
|
||||||
|
@ -468,9 +469,10 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tc
|
||||||
TyChar |
|
TyChar |
|
||||||
TyStr |
|
TyStr |
|
||||||
TyBox(_) |
|
TyBox(_) |
|
||||||
TySlice(_) |
|
TySlice(_) => {}
|
||||||
TyError => {}
|
|
||||||
TyInfer(_) => bug!()
|
TyError |
|
||||||
|
TyInfer(_) => bug!("TypeIdHasher: unexpected type {}", ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
ty.super_visit_with(self)
|
ty.super_visit_with(self)
|
||||||
|
@ -478,7 +480,7 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tc
|
||||||
|
|
||||||
fn visit_region(&mut self, r: &'tcx ty::Region) -> bool {
|
fn visit_region(&mut self, r: &'tcx ty::Region) -> bool {
|
||||||
match *r {
|
match *r {
|
||||||
ty::ReStatic | ty::ReErased => {
|
ty::ReErased => {
|
||||||
self.hash::<u32>(0);
|
self.hash::<u32>(0);
|
||||||
}
|
}
|
||||||
ty::ReLateBound(db, ty::BrAnon(i)) => {
|
ty::ReLateBound(db, ty::BrAnon(i)) => {
|
||||||
|
@ -486,6 +488,7 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tc
|
||||||
self.hash::<u32>(db.depth);
|
self.hash::<u32>(db.depth);
|
||||||
self.hash(i);
|
self.hash(i);
|
||||||
}
|
}
|
||||||
|
ty::ReStatic |
|
||||||
ty::ReEmpty |
|
ty::ReEmpty |
|
||||||
ty::ReEarlyBound(..) |
|
ty::ReEarlyBound(..) |
|
||||||
ty::ReLateBound(..) |
|
ty::ReLateBound(..) |
|
||||||
|
@ -493,7 +496,7 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tc
|
||||||
ty::ReScope(..) |
|
ty::ReScope(..) |
|
||||||
ty::ReVar(..) |
|
ty::ReVar(..) |
|
||||||
ty::ReSkolemized(..) => {
|
ty::ReSkolemized(..) => {
|
||||||
bug!("unexpected region found when hashing a type")
|
bug!("TypeIdHasher: unexpected region {:?}", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
@ -92,6 +92,8 @@ pub fn get_drop_glue_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
t: Ty<'tcx>) -> Ty<'tcx> {
|
t: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
assert!(t.is_normalized_for_trans());
|
assert!(t.is_normalized_for_trans());
|
||||||
|
|
||||||
|
let t = tcx.erase_regions(&t);
|
||||||
|
|
||||||
// Even if there is no dtor for t, there might be one deeper down and we
|
// Even if there is no dtor for t, there might be one deeper down and we
|
||||||
// might need to pass in the vtable ptr.
|
// might need to pass in the vtable ptr.
|
||||||
if !type_is_sized(tcx, t) {
|
if !type_is_sized(tcx, t) {
|
||||||
|
|
|
@ -87,4 +87,8 @@ pub fn main() {
|
||||||
assert_eq!(other1::id_u32_iterator(), other2::id_u32_iterator());
|
assert_eq!(other1::id_u32_iterator(), other2::id_u32_iterator());
|
||||||
assert!(other1::id_i32_iterator() != other1::id_u32_iterator());
|
assert!(other1::id_i32_iterator() != other1::id_u32_iterator());
|
||||||
assert!(TypeId::of::<other1::I32Iterator>() != TypeId::of::<other1::U32Iterator>());
|
assert!(TypeId::of::<other1::I32Iterator>() != TypeId::of::<other1::U32Iterator>());
|
||||||
|
|
||||||
|
// Check fn pointer against collisions
|
||||||
|
assert!(TypeId::of::<fn(fn(A) -> A) -> A>() !=
|
||||||
|
TypeId::of::<fn(fn() -> A, A) -> A>());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue