Trait rustc_ap_rustc_data_structures::stable_hasher::HashStable [−][src]
pub trait HashStable<CTX> { fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher); }
Expand description
Something that implements HashStable<CTX>
can be hashed in a way that is
stable across multiple compilation sessions.
Note that HashStable
imposes rather more strict requirements than usual
hash functions:
-
Stable hashes are sometimes used as identifiers. Therefore they must conform to the corresponding
PartialEq
implementations:x == y
implieshash_stable(x) == hash_stable(y)
, andx != y
implieshash_stable(x) != hash_stable(y)
.
That second condition is usually not required for hash functions (e.g.
Hash
). In practice this means thathash_stable
must feed any information into the hasher that aPartialEq
comparison takes into account. See #49300 for an example where violating this invariant has caused trouble in the past. -
hash_stable()
must be independent of the current compilation session. E.g. they must not hash memory addresses or other things that are “randomly” assigned per compilation session. -
hash_stable()
must be independent of the host architecture. TheStableHasher
takes care of endianness andisize
/usize
platform differences.
Required methods
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher)
Implementations on Foreign Types
impl<T1, T2, T3, CTX> HashStable<CTX> for (T1, T2, T3) where
T1: HashStable<CTX>,
T2: HashStable<CTX>,
T3: HashStable<CTX>,
impl<T1, T2, T3, CTX> HashStable<CTX> for (T1, T2, T3) where
T1: HashStable<CTX>,
T2: HashStable<CTX>,
T3: HashStable<CTX>,
impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4) where
T1: HashStable<CTX>,
T2: HashStable<CTX>,
T3: HashStable<CTX>,
T4: HashStable<CTX>,
impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4) where
T1: HashStable<CTX>,
T2: HashStable<CTX>,
T3: HashStable<CTX>,
T4: HashStable<CTX>,
impl<K, V, R, CTX> HashStable<CTX> for IndexMap<K, V, R> where
K: HashStable<CTX> + Eq + Hash,
V: HashStable<CTX>,
R: BuildHasher,
impl<K, V, R, CTX> HashStable<CTX> for IndexMap<K, V, R> where
K: HashStable<CTX> + Eq + Hash,
V: HashStable<CTX>,
R: BuildHasher,
impl<K, R, CTX> HashStable<CTX> for IndexSet<K, R> where
K: HashStable<CTX> + Eq + Hash,
R: BuildHasher,
impl<K, R, CTX> HashStable<CTX> for IndexSet<K, R> where
K: HashStable<CTX> + Eq + Hash,
R: BuildHasher,
impl<T1, T2, CTX> HashStable<CTX> for Result<T1, T2> where
T1: HashStable<CTX>,
T2: HashStable<CTX>,
impl<T1, T2, CTX> HashStable<CTX> for Result<T1, T2> where
T1: HashStable<CTX>,
T2: HashStable<CTX>,
impl<K, V, R, HCX> HashStable<HCX> for HashMap<K, V, R> where
K: ToStableHashKey<HCX> + Eq,
V: HashStable<HCX>,
R: BuildHasher,
impl<K, V, R, HCX> HashStable<HCX> for HashMap<K, V, R> where
K: ToStableHashKey<HCX> + Eq,
V: HashStable<HCX>,
R: BuildHasher,
impl<K, R, HCX> HashStable<HCX> for HashSet<K, R> where
K: ToStableHashKey<HCX> + Eq,
R: BuildHasher,
impl<K, R, HCX> HashStable<HCX> for HashSet<K, R> where
K: ToStableHashKey<HCX> + Eq,
R: BuildHasher,
impl<K, V, HCX> HashStable<HCX> for BTreeMap<K, V> where
K: ToStableHashKey<HCX>,
V: HashStable<HCX>,
impl<K, V, HCX> HashStable<HCX> for BTreeMap<K, V> where
K: ToStableHashKey<HCX>,
V: HashStable<HCX>,
Implementors
impl<I: Idx, K, V, C> HashStable<C> for SortedIndexMultiMap<I, K, V> where
K: HashStable<C>,
V: HashStable<C>,
impl<K, V, CTX> HashStable<CTX> for VecMap<K, V> where
K: HashStable<CTX> + Eq,
V: HashStable<CTX>,
impl<P, T, HCX, const COMPARE_PACKED: bool> HashStable<HCX> for CopyTaggedPtr<P, T, COMPARE_PACKED> where
P: Pointer + HashStable<HCX>,
T: Tag + HashStable<HCX>,
impl<P, T, HCX, const COMPARE_PACKED: bool> HashStable<HCX> for TaggedPtr<P, T, COMPARE_PACKED> where
P: Pointer + HashStable<HCX>,
T: Tag + HashStable<HCX>,