From a73c5171f8a55fa698b38014f62bacdfcab0dea0 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 25 Nov 2018 14:20:42 +0000 Subject: [PATCH] Add pointer equality to PartialEq for PackageId --- src/cargo/core/package_id.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/package_id.rs b/src/cargo/core/package_id.rs index 7231c137251..885d2c61caf 100644 --- a/src/cargo/core/package_id.rs +++ b/src/cargo/core/package_id.rs @@ -3,6 +3,7 @@ use std::fmt::{self, Formatter}; use std::hash; use std::hash::Hash; use std::path::Path; +use std::ptr; use std::sync::Mutex; use semver; @@ -18,7 +19,7 @@ lazy_static! { } /// Identifier for a specific version of a package in a specific source. -#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Clone, Copy, Eq, Hash, PartialOrd, Ord)] pub struct PackageId { inner: &'static PackageIdInner, } @@ -96,6 +97,15 @@ impl<'de> de::Deserialize<'de> for PackageId { } } +impl PartialEq for PackageId { + fn eq(&self, other: &PackageId) -> bool { + if ptr::eq(self.inner, other.inner) { + return true; + } + (*self.inner).eq(&*other.inner) + } +} + impl PackageId { pub fn new(name: &str, version: T, sid: SourceId) -> CargoResult { let v = version.to_semver()?;