From 6dbd84640f7efa2e6d8a2bc13e9a30cbe5c3f96c Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 8 Aug 2017 18:11:39 +0200 Subject: [PATCH] Erase/anonymize regions while computing TypeId hash. --- src/librustc/ty/util.rs | 5 +++++ src/test/run-pass/type-id-higher-rank.rs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index df4bbad3859f4..ca95ff5722a12 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -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); diff --git a/src/test/run-pass/type-id-higher-rank.rs b/src/test/run-pass/type-id-higher-rank.rs index 827b05c0801e1..2865b5d04e5be 100644 --- a/src/test/run-pass/type-id-higher-rank.rs +++ b/src/test/run-pass/type-id-higher-rank.rs @@ -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(&'a isize) -> &'a usize)>(); + let k = TypeId::of:: fn(&'b isize) -> &'b usize)>(); + assert_eq!(j, k); } // Boxed unboxed closures {