Skip to content

Commit a04c09a

Browse files
committed
Document how the HashN types are different from Fingerprint
1 parent 0445fbd commit a04c09a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

compiler/rustc_data_structures/src/hashes.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
//! rustc encodes a lot of hashes. If hashes are stored as `u64` or `u128`, a `derive(Encodable)`
2+
//! will apply varint encoding to the hashes, which is less efficient than directly encoding the 8
3+
//! or 16 bytes of the hash.
4+
//!
5+
//! The types in this module represent 64-bit or 128-bit hashes produced by a `StableHasher`.
6+
//! `Hash64` and `Hash128` expose some utilty functions to encourage users to not extract the inner
7+
//! hash value as an integer type and accidentally apply varint encoding to it.
8+
//!
9+
//! In contrast with `Fingerprint`, users of these types cannot and should not attempt to construct
10+
//! and decompose these types into constitutent pieces. The point of these types is only to
11+
//! connect the fact that they can only be produced by a `StableHasher` to their
12+
//! `Encode`/`Decode` impls.
13+
14+
use crate::stable_hasher::{StableHasher, StableHasherResult};
115
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
216
use std::fmt;
317
use std::ops::BitXorAssign;
4-
use crate::stable_hasher::{StableHasher, StableHasherResult};
518

619
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
720
pub struct Hash64 {
@@ -74,9 +87,7 @@ impl Hash128 {
7487

7588
#[inline]
7689
pub fn wrapping_add(self, other: Self) -> Self {
77-
Self {
78-
inner: self.inner.wrapping_add(other.inner),
79-
}
90+
Self { inner: self.inner.wrapping_add(other.inner) }
8091
}
8192

8293
#[inline]

0 commit comments

Comments
 (0)