summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_data_structures/src/svh.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_data_structures/src/svh.rs')
-rw-r--r--compiler/rustc_data_structures/src/svh.rs40
1 files changed, 9 insertions, 31 deletions
diff --git a/compiler/rustc_data_structures/src/svh.rs b/compiler/rustc_data_structures/src/svh.rs
index 61654b9e8..71679086f 100644
--- a/compiler/rustc_data_structures/src/svh.rs
+++ b/compiler/rustc_data_structures/src/svh.rs
@@ -5,58 +5,36 @@
//! mismatches where we have two versions of the same crate that were
//! compiled from distinct sources.
-use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
+use crate::fingerprint::Fingerprint;
use std::fmt;
-use std::hash::{Hash, Hasher};
use crate::stable_hasher;
-#[derive(Copy, Clone, PartialEq, Eq, Debug)]
+#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable, Decodable, Hash)]
pub struct Svh {
- hash: u64,
+ hash: Fingerprint,
}
impl Svh {
/// Creates a new `Svh` given the hash. If you actually want to
/// compute the SVH from some HIR, you want the `calculate_svh`
/// function found in `rustc_incremental`.
- pub fn new(hash: u64) -> Svh {
+ pub fn new(hash: Fingerprint) -> Svh {
Svh { hash }
}
- pub fn as_u64(&self) -> u64 {
- self.hash
+ pub fn as_u128(self) -> u128 {
+ self.hash.as_u128()
}
- pub fn to_string(&self) -> String {
- format!("{:016x}", self.hash)
- }
-}
-
-impl Hash for Svh {
- fn hash<H>(&self, state: &mut H)
- where
- H: Hasher,
- {
- self.hash.to_le().hash(state);
+ pub fn to_hex(self) -> String {
+ format!("{:032x}", self.hash.as_u128())
}
}
impl fmt::Display for Svh {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.pad(&self.to_string())
- }
-}
-
-impl<S: Encoder> Encodable<S> for Svh {
- fn encode(&self, s: &mut S) {
- s.emit_u64(self.as_u64().to_le());
- }
-}
-
-impl<D: Decoder> Decodable<D> for Svh {
- fn decode(d: &mut D) -> Svh {
- Svh::new(u64::from_le(d.read_u64()))
+ f.pad(&self.to_hex())
}
}