From c51e36ab1134f3dec47ddbdd13de9d10412e429e Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 18 Dec 2024 13:08:42 +0100 Subject: [PATCH] Hash paths relative to the workspace into metadata. Fixes #13586 --- src/cargo/core/source_id.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/cargo/core/source_id.rs b/src/cargo/core/source_id.rs index 501c88cba72..bb7f6f81853 100644 --- a/src/cargo/core/source_id.rs +++ b/src/cargo/core/source_id.rs @@ -534,17 +534,12 @@ impl SourceId { /// Hashes `self`. /// - /// For paths, remove the workspace prefix so the same source will give the + /// For paths, make it relative to the workspace root so the same source will give the /// same hash in different locations, helping reproducible builds. pub fn stable_hash(self, workspace: &Path, into: &mut S) { if self.is_path() { - if let Ok(p) = self - .inner - .url - .to_file_path() - .unwrap() - .strip_prefix(workspace) - { + let path = self.inner.url.to_file_path().unwrap(); + if let Some(p) = pathdiff::diff_paths(path, workspace) { self.inner.kind.hash(into); p.to_str().unwrap().hash(into); return;