Skip to content

Commit 6dbd846

Browse files
Erase/anonymize regions while computing TypeId hash.
1 parent d07dd4a commit 6dbd846

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/librustc/ty/util.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
214214
let mut hasher = StableHasher::new();
215215
let mut hcx = StableHashingContext::new(self);
216216

217+
// We want the type_id be independent of the types free regions, so we
218+
// erase them. The erase_regions() call will also anonymize bound
219+
// regions, which is desirable too.
220+
let ty = self.erase_regions(&ty);
221+
217222
hcx.while_hashing_spans(false, |hcx| {
218223
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
219224
ty.hash_stable(hcx, &mut hasher);

src/test/run-pass/type-id-higher-rank.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ fn main() {
4545
assert!(g != h);
4646
assert!(g != i);
4747
assert!(h != i);
48+
49+
// Make sure lifetime anonymization handles nesting correctly
50+
let j = TypeId::of::<fn(for<'a> fn(&'a isize) -> &'a usize)>();
51+
let k = TypeId::of::<fn(for<'b> fn(&'b isize) -> &'b usize)>();
52+
assert_eq!(j, k);
4853
}
4954
// Boxed unboxed closures
5055
{

0 commit comments

Comments
 (0)