mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Move the custom equality up to SourceId
That way we: * preserve that SourceIds that have slightly different URLs are actually equal * make SourceIdInner lawful in its Hash/Eq definition.
This commit is contained in:
parent
3d91b79541
commit
653ce4d4c3
@ -27,7 +27,7 @@ pub struct SourceId {
|
|||||||
inner: &'static SourceIdInner,
|
inner: &'static SourceIdInner,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, Clone, Debug, Hash)]
|
#[derive(PartialEq, Eq, Clone, Debug, Hash)]
|
||||||
struct SourceIdInner {
|
struct SourceIdInner {
|
||||||
/// The source URL
|
/// The source URL
|
||||||
url: Url,
|
url: Url,
|
||||||
@ -341,12 +341,6 @@ impl SourceId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for SourceId {
|
|
||||||
fn eq(&self, other: &SourceId) -> bool {
|
|
||||||
(*self.inner).eq(&*other.inner)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialOrd for SourceId {
|
impl PartialOrd for SourceId {
|
||||||
fn partial_cmp(&self, other: &SourceId) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &SourceId) -> Option<Ordering> {
|
||||||
Some(self.cmp(other))
|
Some(self.cmp(other))
|
||||||
@ -440,24 +434,20 @@ impl fmt::Display for SourceId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This custom implementation handles situations such as when two git sources
|
// Custom equality defined as canonical URL equality for git sources and
|
||||||
// point at *almost* the same URL, but not quite, even when they actually point
|
// URL equality for other sources, ignoring the `precise` and `name` fields.
|
||||||
// to the same repository.
|
impl PartialEq for SourceId {
|
||||||
/// This method tests for self and other values to be equal, and is used by ==.
|
fn eq(&self, other: &SourceId) -> bool {
|
||||||
///
|
if self.inner.kind != other.inner.kind {
|
||||||
/// For git repositories, the canonical url is checked.
|
|
||||||
impl PartialEq for SourceIdInner {
|
|
||||||
fn eq(&self, other: &SourceIdInner) -> bool {
|
|
||||||
if self.kind != other.kind {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if self.url == other.url {
|
if self.inner.url == other.inner.url {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
match (&self.kind, &other.kind) {
|
match (&self.inner.kind, &other.inner.kind) {
|
||||||
(&Kind::Git(ref ref1), &Kind::Git(ref ref2)) => {
|
(Kind::Git(ref1), Kind::Git(ref2)) => {
|
||||||
ref1 == ref2 && self.canonical_url == other.canonical_url
|
ref1 == ref2 && self.inner.canonical_url == other.inner.canonical_url
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user