]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_ast/src/crate_disambiguator.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / compiler / rustc_ast / src / crate_disambiguator.rs
CommitLineData
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
4use rustc_data_structures::fingerprint::Fingerprint;
5use rustc_data_structures::{base_n, impl_stable_hash_via_hash};
6
7use 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
13pub struct CrateDisambiguator(Fingerprint);
14
15impl CrateDisambiguator {
16 pub fn to_fingerprint(self) -> Fingerprint {
17 self.0
18 }
19}
20
21impl 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
29impl From<Fingerprint> for CrateDisambiguator {
30 fn from(fingerprint: Fingerprint) -> CrateDisambiguator {
31 CrateDisambiguator(fingerprint)
32 }
33}
34
35impl_stable_hash_via_hash!(CrateDisambiguator);