Skip to content
/ rust Public
forked from rust-lang/rust

Manually implement a more general HashStable for RustcVersion #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_attr/src/lib.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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);
}
}