Skip to content

Commit a73c517

Browse files
committed
Add pointer equality to PartialEq for PackageId
1 parent 0abfcc0 commit a73c517

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/cargo/core/package_id.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::fmt::{self, Formatter};
33
use std::hash;
44
use std::hash::Hash;
55
use std::path::Path;
6+
use std::ptr;
67
use std::sync::Mutex;
78

89
use semver;
@@ -18,7 +19,7 @@ lazy_static! {
1819
}
1920

2021
/// Identifier for a specific version of a package in a specific source.
21-
#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
22+
#[derive(Clone, Copy, Eq, Hash, PartialOrd, Ord)]
2223
pub struct PackageId {
2324
inner: &'static PackageIdInner,
2425
}
@@ -96,6 +97,15 @@ impl<'de> de::Deserialize<'de> for PackageId {
9697
}
9798
}
9899

100+
impl PartialEq for PackageId {
101+
fn eq(&self, other: &PackageId) -> bool {
102+
if ptr::eq(self.inner, other.inner) {
103+
return true;
104+
}
105+
(*self.inner).eq(&*other.inner)
106+
}
107+
}
108+
99109
impl PackageId {
100110
pub fn new<T: ToSemver>(name: &str, version: T, sid: SourceId) -> CargoResult<PackageId> {
101111
let v = version.to_semver()?;

0 commit comments

Comments
 (0)