From d9adba1cf59926770d65dbb5101610c4778ce44e Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 24 Feb 2025 09:46:14 -1000 Subject: [PATCH] Use a `Box` for `Yanked` on `File` (#11755) ## Summary See: https://github.com/astral-sh/uv/pull/11715. --- crates/uv-client/src/html.rs | 2 +- crates/uv-distribution-types/src/file.rs | 2 +- crates/uv-distribution-types/src/resolved.rs | 6 ++++-- crates/uv-pypi-types/src/simple_json.rs | 2 +- crates/uv-resolver/src/version_map.rs | 12 +++++++----- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/uv-client/src/html.rs b/crates/uv-client/src/html.rs index a7733bf69..4e1adb468 100644 --- a/crates/uv-client/src/html.rs +++ b/crates/uv-client/src/html.rs @@ -184,7 +184,7 @@ impl SimpleHtml { let yanked = if let Some(yanked) = link.attributes().get("data-yanked").flatten() { let yanked = std::str::from_utf8(yanked.as_bytes())?; let yanked = html_escape::decode_html_entities(yanked); - Some(Yanked::Reason(yanked.into())) + Some(Box::new(Yanked::Reason(yanked.into()))) } else { None }; diff --git a/crates/uv-distribution-types/src/file.rs b/crates/uv-distribution-types/src/file.rs index 9dd503a14..52de0c5e9 100644 --- a/crates/uv-distribution-types/src/file.rs +++ b/crates/uv-distribution-types/src/file.rs @@ -33,7 +33,7 @@ pub struct File { // milliseconds. pub upload_time_utc_ms: Option, pub url: FileLocation, - pub yanked: Option, + pub yanked: Option>, } impl File { diff --git a/crates/uv-distribution-types/src/resolved.rs b/crates/uv-distribution-types/src/resolved.rs index d7441d88f..a1eaac3f2 100644 --- a/crates/uv-distribution-types/src/resolved.rs +++ b/crates/uv-distribution-types/src/resolved.rs @@ -75,8 +75,10 @@ impl ResolvedDist { pub fn yanked(&self) -> Option<&Yanked> { match self { Self::Installable { dist, .. } => match dist.as_ref() { - Dist::Source(SourceDist::Registry(sdist)) => sdist.file.yanked.as_ref(), - Dist::Built(BuiltDist::Registry(wheel)) => wheel.best_wheel().file.yanked.as_ref(), + Dist::Source(SourceDist::Registry(sdist)) => sdist.file.yanked.as_deref(), + Dist::Built(BuiltDist::Registry(wheel)) => { + wheel.best_wheel().file.yanked.as_deref() + } _ => None, }, Self::Installed { .. } => None, diff --git a/crates/uv-pypi-types/src/simple_json.rs b/crates/uv-pypi-types/src/simple_json.rs index d61518b72..eef5889f2 100644 --- a/crates/uv-pypi-types/src/simple_json.rs +++ b/crates/uv-pypi-types/src/simple_json.rs @@ -54,7 +54,7 @@ pub struct File { pub size: Option, pub upload_time: Option, pub url: String, - pub yanked: Option, + pub yanked: Option>, } fn deserialize_version_specifiers_lenient<'de, D>( diff --git a/crates/uv-resolver/src/version_map.rs b/crates/uv-resolver/src/version_map.rs index 8ec357454..fca6b86c1 100644 --- a/crates/uv-resolver/src/version_map.rs +++ b/crates/uv-resolver/src/version_map.rs @@ -417,7 +417,7 @@ impl VersionMapLazy { }; // Prioritize amongst all available files. - let yanked = file.yanked.clone(); + let yanked = file.yanked.as_deref(); let hashes = file.hashes.clone(); match filename { DistFilename::WheelFilename(filename) => { @@ -472,7 +472,7 @@ impl VersionMapLazy { name: &PackageName, version: &Version, hashes: &[HashDigest], - yanked: Option, + yanked: Option<&Yanked>, excluded: bool, upload_time: Option, ) -> SourceDistCompatibility { @@ -491,7 +491,9 @@ impl VersionMapLazy { // Check if yanked if let Some(yanked) = yanked { if yanked.is_yanked() && !self.allowed_yanks.contains(name, version) { - return SourceDistCompatibility::Incompatible(IncompatibleSource::Yanked(yanked)); + return SourceDistCompatibility::Incompatible(IncompatibleSource::Yanked( + yanked.clone(), + )); } } @@ -519,7 +521,7 @@ impl VersionMapLazy { name: &PackageName, version: &Version, hashes: &[HashDigest], - yanked: Option, + yanked: Option<&Yanked>, excluded: bool, upload_time: Option, ) -> WheelCompatibility { @@ -536,7 +538,7 @@ impl VersionMapLazy { // Check if yanked if let Some(yanked) = yanked { if yanked.is_yanked() && !self.allowed_yanks.contains(name, version) { - return WheelCompatibility::Incompatible(IncompatibleWheel::Yanked(yanked)); + return WheelCompatibility::Incompatible(IncompatibleWheel::Yanked(yanked.clone())); } }