From 47eb6ee42b046338b91a9c0131b6283a348ff12d Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 3 Jul 2024 08:36:46 -0400 Subject: [PATCH] Fix cache key collisions for paths with separators (#12159) Closes https://github.com/astral-sh/ruff/issues/12158 Hashing `Path` does not take into account path separators so `foo/bar` is the same as `foobar` which is no good for our case. I'm guessing this is an upstream bug, perhaps introduced by https://github.com/rust-lang/rust/commit/45082b077b4991361f451701d0a9467ce123acdf? I'm investigating that further. --- crates/ruff_cache/src/cache_key.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ruff_cache/src/cache_key.rs b/crates/ruff_cache/src/cache_key.rs index 1208c40100..de66961dce 100644 --- a/crates/ruff_cache/src/cache_key.rs +++ b/crates/ruff_cache/src/cache_key.rs @@ -350,7 +350,9 @@ impl CacheKey for BTreeMap { impl CacheKey for Path { #[inline] fn cache_key(&self, state: &mut CacheKeyHasher) { - self.hash(&mut *state); + for component in self.components() { + component.hash(&mut *state); + } } }