diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2017-08-08 18:11:39 +0200 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2017-08-09 14:09:48 +0200 |
| commit | 6dbd84640f7efa2e6d8a2bc13e9a30cbe5c3f96c (patch) | |
| tree | c4d510a098f5f6d2b1dde0d3ffaf5d0448c726bd | |
| parent | d07dd4ab444bb14746c3cc80186c979e5c51c3a1 (diff) | |
| download | rust-6dbd84640f7efa2e6d8a2bc13e9a30cbe5c3f96c.tar.gz rust-6dbd84640f7efa2e6d8a2bc13e9a30cbe5c3f96c.zip | |
Erase/anonymize regions while computing TypeId hash.
| -rw-r--r-- | src/librustc/ty/util.rs | 5 | ||||
| -rw-r--r-- | src/test/run-pass/type-id-higher-rank.rs | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index df4bbad3859..ca95ff5722a 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 827b05c0801..2865b5d04e5 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(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 { |
