Skip to main content

rustc_data_structures/
svh.rs

1//! Calculation and management of a Strict Version Hash for crates
2//!
3//! The SVH is used for incremental compilation to track when HIR
4//! nodes have changed between compilations, and also to detect
5//! mismatches where we have two versions of the same crate that were
6//! compiled from distinct sources.
7
8use std::fmt;
9
10use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
11
12use crate::fingerprint::Fingerprint;
13use crate::stable_hasher;
14
15#[derive(#[automatically_derived]
impl ::core::marker::Copy for Svh { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Svh {
    #[inline]
    fn clone(&self) -> Svh {
        let _: ::core::clone::AssertParamIsClone<Fingerprint>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::cmp::PartialEq for Svh {
    #[inline]
    fn eq(&self, other: &Svh) -> bool { self.hash == other.hash }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Svh {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_receiver_is_total_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Fingerprint>;
    }
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for Svh {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "Svh", "hash",
            &&self.hash)
    }
}Debug, const _: () =
    {
        impl<__E: ::rustc_serialize::Encoder>
            ::rustc_serialize::Encodable<__E> for Svh {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    Svh { hash: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable_NoContext, const _: () =
    {
        impl<__D: ::rustc_serialize::Decoder>
            ::rustc_serialize::Decodable<__D> for Svh {
            fn decode(__decoder: &mut __D) -> Self {
                Svh { hash: ::rustc_serialize::Decodable::decode(__decoder) }
            }
        }
    };Decodable_NoContext, #[automatically_derived]
impl ::core::hash::Hash for Svh {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&self.hash, state)
    }
}Hash)]
16pub struct Svh {
17    hash: Fingerprint,
18}
19
20impl Svh {
21    /// Creates a new `Svh` given the hash. If you actually want to
22    /// compute the SVH from some HIR, you want the `calculate_svh`
23    /// function found in `rustc_incremental`.
24    pub fn new(hash: Fingerprint) -> Svh {
25        Svh { hash }
26    }
27
28    pub fn as_u128(self) -> u128 {
29        self.hash.as_u128()
30    }
31
32    pub fn to_hex(self) -> String {
33        ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0:032x}", self.hash.as_u128()))
    })format!("{:032x}", self.hash.as_u128())
34    }
35}
36
37impl fmt::Display for Svh {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        f.pad(&self.to_hex())
40    }
41}
42
43impl<T> stable_hasher::HashStable<T> for Svh {
44    #[inline]
45    fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) {
46        let Svh { hash } = *self;
47        hash.hash_stable(ctx, hasher);
48    }
49}