Skip to content

Commit 06811d8

Browse files
committed
manual impl of hash
1 parent d8b7c07 commit 06811d8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/cargo-util-schemas/src/core/source_kind.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::cmp::Ordering;
22

33
/// The possible kinds of code source.
4-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
4+
#[derive(Debug, Clone, PartialEq, Eq)]
55
pub enum SourceKind {
66
/// A git repository.
77
Git(GitReference),
@@ -17,6 +17,19 @@ pub enum SourceKind {
1717
Directory,
1818
}
1919

20+
// The hash here is important for what folder packages get downloaded into.
21+
// Changes trigger all users to download another copy of their crates.
22+
// So the `stable_hash` test checks that we only change it intentionally.
23+
// We implement hash manually to callout the stability impact.
24+
impl std::hash::Hash for SourceKind {
25+
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
26+
core::mem::discriminant(self).hash(state);
27+
if let SourceKind::Git(git) = self {
28+
git.hash(state);
29+
}
30+
}
31+
}
32+
2033
impl SourceKind {
2134
pub fn protocol(&self) -> Option<&str> {
2235
match self {

0 commit comments

Comments
 (0)