Skip to content

Commit

Permalink
Manually implement a more general HashStable for RustcVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 27, 2023
1 parent b7debe3 commit 0fc378a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_attr/src/lib.rs
Expand Up @@ -27,6 +27,6 @@ pub use StabilityLevel::*;

pub use rustc_ast::attr::*;

pub(crate) use rustc_session::HashStableContext;
pub(crate) use rustc_ast::HashStableContext;

fluent_messages! { "../messages.ftl" }
16 changes: 15 additions & 1 deletion compiler/rustc_session/src/version.rs
@@ -1,7 +1,8 @@
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use std::fmt::{self, Display};

#[derive(Encodable, Decodable, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(HashStable_Generic)]
//#[derive(HashStable_Generic)]
pub struct RustcVersion {
pub major: u16,
pub minor: u16,
Expand All @@ -17,3 +18,16 @@ impl Display for RustcVersion {
write!(formatter, "{}.{}.{}", self.major, self.minor, self.patch)
}
}

// Handwritten because #[derive(HashStable_Generic)] would generate a stricter
// `Ctx: rustc_session::HashStableContext` bound.
impl<Ctx> HashStable<Ctx> for RustcVersion
where
Ctx: rustc_ast::HashStableContext,
{
fn hash_stable(&self, hcx: &mut Ctx, hasher: &mut StableHasher) {
self.major.hash_stable(hcx, hasher);
self.minor.hash_stable(hcx, hasher);
self.patch.hash_stable(hcx, hasher);
}
}

0 comments on commit 0fc378a

Please sign in to comment.