diff --git a/crates/pep508-rs/src/verbatim_url.rs b/crates/pep508-rs/src/verbatim_url.rs index 31d794ebaa37..63d0c32dbe1c 100644 --- a/crates/pep508-rs/src/verbatim_url.rs +++ b/crates/pep508-rs/src/verbatim_url.rs @@ -1,6 +1,8 @@ use regex::Regex; use std::borrow::Cow; +use std::cmp::Ordering; use std::fmt::Debug; +use std::hash::Hash; use std::ops::Deref; use std::path::{Path, PathBuf}; use std::sync::LazyLock; @@ -12,18 +14,26 @@ use uv_fs::{normalize_absolute_path, normalize_url_path, Simplified}; use crate::Pep508Url; /// A wrapper around [`Url`] that preserves the original string. -#[derive(Debug, Clone, Eq, derivative::Derivative)] -#[derivative(PartialEq, Hash, Ord)] +#[derive(Debug, Clone, Eq)] pub struct VerbatimUrl { /// The parsed URL. url: Url, /// The URL as it was provided by the user. - #[derivative(PartialEq = "ignore")] - #[derivative(Ord = "ignore")] - #[derivative(Hash = "ignore")] given: Option, } +impl Hash for VerbatimUrl { + fn hash(&self, state: &mut H) { + self.url.hash(state); + } +} + +impl PartialEq for VerbatimUrl { + fn eq(&self, other: &Self) -> bool { + self.url == other.url + } +} + impl VerbatimUrl { /// Create a [`VerbatimUrl`] from a [`Url`]. pub fn from_url(url: Url) -> Self { @@ -167,12 +177,14 @@ impl VerbatimUrl { } } -// This impl is written out because the `derive` doesn't seem to get it right. -// Or does it in a way where Clippy complains about non-canonical `PartialOrd` -// impls. So we just do it by hand by deferring to the derived `Ord` impl. This -// guarantees they are consistent. +impl Ord for VerbatimUrl { + fn cmp(&self, other: &Self) -> Ordering { + self.url.cmp(&other.url) + } +} + impl PartialOrd for VerbatimUrl { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } }