From 06811d8594826611f19dc6b97404ae8cedafb167 Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Tue, 7 Jan 2025 22:12:22 +0000 Subject: [PATCH] manual impl of hash --- crates/cargo-util-schemas/src/core/source_kind.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/cargo-util-schemas/src/core/source_kind.rs b/crates/cargo-util-schemas/src/core/source_kind.rs index a67c80aee..379479111 100644 --- a/crates/cargo-util-schemas/src/core/source_kind.rs +++ b/crates/cargo-util-schemas/src/core/source_kind.rs @@ -1,7 +1,7 @@ use std::cmp::Ordering; /// The possible kinds of code source. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum SourceKind { /// A git repository. Git(GitReference), @@ -17,6 +17,19 @@ pub enum SourceKind { Directory, } +// The hash here is important for what folder packages get downloaded into. +// Changes trigger all users to download another copy of their crates. +// So the `stable_hash` test checks that we only change it intentionally. +// We implement hash manually to callout the stability impact. +impl std::hash::Hash for SourceKind { + fn hash(&self, state: &mut H) { + core::mem::discriminant(self).hash(state); + if let SourceKind::Git(git) = self { + git.hash(state); + } + } +} + impl SourceKind { pub fn protocol(&self) -> Option<&str> { match self {