Skip to content

Commit

Permalink
Erase/anonymize regions while computing TypeId hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Aug 9, 2017
1 parent d07dd4a commit 6dbd846
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustc/ty/util.rs
Expand Up @@ -214,6 +214,11 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
let mut hasher = StableHasher::new();
let mut hcx = StableHashingContext::new(self);

// We want the type_id be independent of the types free regions, so we
// erase them. The erase_regions() call will also anonymize bound
// regions, which is desirable too.
let ty = self.erase_regions(&ty);

hcx.while_hashing_spans(false, |hcx| {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
ty.hash_stable(hcx, &mut hasher);
Expand Down
5 changes: 5 additions & 0 deletions src/test/run-pass/type-id-higher-rank.rs
Expand Up @@ -45,6 +45,11 @@ fn main() {
assert!(g != h);
assert!(g != i);
assert!(h != i);

// Make sure lifetime anonymization handles nesting correctly
let j = TypeId::of::<fn(for<'a> fn(&'a isize) -> &'a usize)>();
let k = TypeId::of::<fn(for<'b> fn(&'b isize) -> &'b usize)>();
assert_eq!(j, k);
}
// Boxed unboxed closures
{
Expand Down

0 comments on commit 6dbd846

Please sign in to comment.