]>
Commit | Line | Data |
---|---|---|
ba9703b0 XL |
1 | // This is here because `rustc_session` wants to refer to it, |
2 | // and so does `rustc_hir`, but `rustc_hir` shouldn't refer to `rustc_session`. | |
3 | ||
4 | use rustc_data_structures::fingerprint::Fingerprint; | |
5 | use rustc_data_structures::{base_n, impl_stable_hash_via_hash}; | |
6 | ||
7 | use std::fmt; | |
8 | ||
9 | /// Hash value constructed out of all the `-C metadata` arguments passed to the | |
10 | /// compiler. Together with the crate-name forms a unique global identifier for | |
11 | /// the crate. | |
3dfed10e | 12 | #[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, Encodable, Decodable)] |
ba9703b0 XL |
13 | pub struct CrateDisambiguator(Fingerprint); |
14 | ||
15 | impl CrateDisambiguator { | |
16 | pub fn to_fingerprint(self) -> Fingerprint { | |
17 | self.0 | |
18 | } | |
19 | } | |
20 | ||
21 | impl fmt::Display for CrateDisambiguator { | |
22 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { | |
23 | let (a, b) = self.0.as_value(); | |
24 | let as_u128 = a as u128 | ((b as u128) << 64); | |
25 | f.write_str(&base_n::encode(as_u128, base_n::CASE_INSENSITIVE)) | |
26 | } | |
27 | } | |
28 | ||
29 | impl From<Fingerprint> for CrateDisambiguator { | |
30 | fn from(fingerprint: Fingerprint) -> CrateDisambiguator { | |
31 | CrateDisambiguator(fingerprint) | |
32 | } | |
33 | } | |
34 | ||
35 | impl_stable_hash_via_hash!(CrateDisambiguator); |