Skip to content

Commit a2726f4

Browse files
committed
rustc: allow less and handle fn pointers in the type hashing algorithm.
1 parent ade79d7 commit a2726f4

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/librustc/ty/util.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,18 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tc
436436
TyInt(i) => self.hash(i),
437437
TyUint(u) => self.hash(u),
438438
TyFloat(f) => self.hash(f),
439-
TyAdt(d, _) => self.def_id(d.did),
440439
TyArray(_, n) => self.hash(n),
441440
TyRawPtr(m) |
442441
TyRef(_, m) => self.hash(m.mutbl),
443442
TyClosure(def_id, _) |
444443
TyAnon(def_id, _) |
445444
TyFnDef(def_id, ..) => self.def_id(def_id),
445+
TyAdt(d, _) => self.def_id(d.did),
446446
TyFnPtr(f) => {
447447
self.hash(f.unsafety);
448448
self.hash(f.abi);
449449
self.hash(f.sig.variadic());
450+
self.hash(f.sig.inputs().skip_binder().len());
450451
}
451452
TyTrait(ref data) => {
452453
self.def_id(data.principal.def_id());
@@ -468,32 +469,34 @@ impl<'a, 'gcx, 'tcx, H: Hasher> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tc
468469
TyChar |
469470
TyStr |
470471
TyBox(_) |
471-
TySlice(_) |
472-
TyError => {}
473-
TyInfer(_) => bug!()
472+
TySlice(_) => {}
473+
474+
TyError |
475+
TyInfer(_) => bug!("TypeIdHasher: unexpected type {}", ty)
474476
}
475477

476478
ty.super_visit_with(self)
477479
}
478480

479481
fn visit_region(&mut self, r: &'tcx ty::Region) -> bool {
480482
match *r {
481-
ty::ReStatic | ty::ReErased => {
483+
ty::ReErased => {
482484
self.hash::<u32>(0);
483485
}
484486
ty::ReLateBound(db, ty::BrAnon(i)) => {
485487
assert!(db.depth > 0);
486488
self.hash::<u32>(db.depth);
487489
self.hash(i);
488490
}
491+
ty::ReStatic |
489492
ty::ReEmpty |
490493
ty::ReEarlyBound(..) |
491494
ty::ReLateBound(..) |
492495
ty::ReFree(..) |
493496
ty::ReScope(..) |
494497
ty::ReVar(..) |
495498
ty::ReSkolemized(..) => {
496-
bug!("unexpected region found when hashing a type")
499+
bug!("TypeIdHasher: unexpected region {:?}", r)
497500
}
498501
}
499502
false

src/librustc_trans/glue.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ pub fn get_drop_glue_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
9292
t: Ty<'tcx>) -> Ty<'tcx> {
9393
assert!(t.is_normalized_for_trans());
9494

95+
let t = tcx.erase_regions(&t);
96+
9597
// Even if there is no dtor for t, there might be one deeper down and we
9698
// might need to pass in the vtable ptr.
9799
if !type_is_sized(tcx, t) {

src/test/run-pass/typeid-intrinsic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ pub fn main() {
8787
assert_eq!(other1::id_u32_iterator(), other2::id_u32_iterator());
8888
assert!(other1::id_i32_iterator() != other1::id_u32_iterator());
8989
assert!(TypeId::of::<other1::I32Iterator>() != TypeId::of::<other1::U32Iterator>());
90+
91+
// Check fn pointer against collisions
92+
assert!(TypeId::of::<fn(fn(A) -> A) -> A>() !=
93+
TypeId::of::<fn(fn() -> A, A) -> A>());
9094
}

0 commit comments

Comments
 (0)