about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2024-03-27 14:57:01 +0100
committerMichael Woerister <michaelwoerister@posteo>2024-03-27 14:57:01 +0100
commit7e4bc4a373574ca727254cc7051ee42cb1102e06 (patch)
treecaef80c8d3b357cd3a04397a08aec4b0aad0be6a /compiler/rustc_data_structures/src
parenta50490c5793516acb03c7b27d26177137b3f16f5 (diff)
downloadrust-7e4bc4a373574ca727254cc7051ee42cb1102e06.tar.gz
rust-7e4bc4a373574ca727254cc7051ee42cb1102e06.zip
Remove and disallow HashStable impl of HashMap.
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/stable_hasher.rs48
1 files changed, 2 insertions, 46 deletions
diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs
index 15691804a94..8418b4bbd47 100644
--- a/compiler/rustc_data_structures/src/stable_hasher.rs
+++ b/compiler/rustc_data_structures/src/stable_hasher.rs
@@ -684,26 +684,11 @@ where
 impl_stable_traits_for_trivial_type!(::std::path::Path);
 impl_stable_traits_for_trivial_type!(::std::path::PathBuf);
 
-impl<K, V, R, HCX> HashStable<HCX> for ::std::collections::HashMap<K, V, R>
-where
-    K: ToStableHashKey<HCX> + Eq,
-    V: HashStable<HCX>,
-    R: BuildHasher,
-{
-    #[inline]
-    fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
-        stable_hash_reduce(hcx, hasher, self.iter(), self.len(), |hasher, hcx, (key, value)| {
-            let key = key.to_stable_hash_key(hcx);
-            key.hash_stable(hcx, hasher);
-            value.hash_stable(hcx, hasher);
-        });
-    }
-}
-
-// It is not safe to implement HashStable for HashSet or any other collection type
+// It is not safe to implement HashStable for HashSet, HashMap or any other collection type
 // with unstable but observable iteration order.
 // See https://github.com/rust-lang/compiler-team/issues/533 for further information.
 impl<V, HCX> !HashStable<HCX> for std::collections::HashSet<V> {}
+impl<K, V, HCX> !HashStable<HCX> for std::collections::HashMap<K, V> {}
 
 impl<K, V, HCX> HashStable<HCX> for ::std::collections::BTreeMap<K, V>
 where
@@ -730,35 +715,6 @@ where
     }
 }
 
-fn stable_hash_reduce<HCX, I, C, F>(
-    hcx: &mut HCX,
-    hasher: &mut StableHasher,
-    mut collection: C,
-    length: usize,
-    hash_function: F,
-) where
-    C: Iterator<Item = I>,
-    F: Fn(&mut StableHasher, &mut HCX, I),
-{
-    length.hash_stable(hcx, hasher);
-
-    match length {
-        1 => {
-            hash_function(hasher, hcx, collection.next().unwrap());
-        }
-        _ => {
-            let hash = collection
-                .map(|value| {
-                    let mut hasher = StableHasher::new();
-                    hash_function(&mut hasher, hcx, value);
-                    hasher.finish::<Hash128>()
-                })
-                .reduce(|accum, value| accum.wrapping_add(value));
-            hash.hash_stable(hcx, hasher);
-        }
-    }
-}
-
 /// Controls what data we do or do not hash.
 /// Whenever a `HashStable` implementation caches its
 /// result, it needs to include `HashingControls` as part