From c8a9119b843c354bc1f471fd868e97bfd24d42bc Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Fri, 20 Dec 2024 21:37:33 +0000 Subject: [PATCH 1/2] make stable_hash not depend on hash --- src/cargo/core/source_id.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/source_id.rs b/src/cargo/core/source_id.rs index 501c88cba72..b85329f6f74 100644 --- a/src/cargo/core/source_id.rs +++ b/src/cargo/core/source_id.rs @@ -532,7 +532,10 @@ impl SourceId { url == CRATES_IO_INDEX || url == CRATES_IO_HTTP_INDEX || is_overridden_crates_io_url(url) } - /// Hashes `self`. + /// Hashes `self` to be used in the name of some Cargo folders, so shouldn't vary. + /// + /// For git and url, `as_str` gives the serialisation of a url (which has a spec) and so + /// insulates against possible changes in how the url crate does hashing. /// /// For paths, remove the workspace prefix so the same source will give the /// same hash in different locations, helping reproducible builds. @@ -550,7 +553,11 @@ impl SourceId { return; } } - self.hash(into) + self.inner.kind.hash(into); + match self.inner.kind { + SourceKind::Git(_) => (&self).inner.canonical_url.hash(into), + _ => (&self).inner.url.as_str().hash(into), + } } pub fn full_eq(self, other: SourceId) -> bool { @@ -665,9 +672,6 @@ impl fmt::Display for SourceId { } } -/// The hash of `SourceId` is used in the name of some Cargo folders, so shouldn't -/// vary. `as_str` gives the serialisation of a url (which has a spec) and so -/// insulates against possible changes in how the url crate does hashing. impl Hash for SourceId { fn hash(&self, into: &mut S) { self.inner.kind.hash(into); From 9c19032ca753506da645302bdb52c76e8c218909 Mon Sep 17 00:00:00 2001 From: Jacob Finkelman Date: Fri, 20 Dec 2024 21:39:20 +0000 Subject: [PATCH 2/2] simplify SourceID Hash --- src/cargo/core/source_id.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cargo/core/source_id.rs b/src/cargo/core/source_id.rs index b85329f6f74..876d34281e9 100644 --- a/src/cargo/core/source_id.rs +++ b/src/cargo/core/source_id.rs @@ -675,10 +675,7 @@ impl fmt::Display for SourceId { impl Hash for SourceId { fn hash(&self, into: &mut S) { self.inner.kind.hash(into); - match self.inner.kind { - SourceKind::Git(_) => self.inner.canonical_url.hash(into), - _ => self.inner.url.as_str().hash(into), - } + self.inner.canonical_url.hash(into); } }