]> git.lizzy.rs Git - rust.git/commitdiff
Erase/anonymize regions while computing TypeId hash.
authorMichael Woerister <michaelwoerister@posteo>
Tue, 8 Aug 2017 16:11:39 +0000 (18:11 +0200)
committerMichael Woerister <michaelwoerister@posteo>
Wed, 9 Aug 2017 12:09:48 +0000 (14:09 +0200)
src/librustc/ty/util.rs
src/test/run-pass/type-id-higher-rank.rs

index df4bbad3859f4ecc46623ed3b7bf30911dc814c4..ca95ff5722a12d03e448b223953987e8745a708a 100644 (file)
@@ -214,6 +214,11 @@ pub fn type_id_hash(self, ty: Ty<'tcx>) -> u64 {
         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);
index 827b05c0801e1eb39b5650defc365315f411b3d3..2865b5d04e5be61d4bdaf6ca522d5dac1c7be7ea 100644 (file)
@@ -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
     {