From c8032976a4b00de7fb35a459cfd710434d5cc0aa Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 25 Aug 2024 13:17:40 +0100 Subject: [PATCH] Workaround for type inference breakage in the time crate https://github.com/rust-lang/rust/issues/127343 --- src/cargo/sources/registry/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/cargo/sources/registry/mod.rs b/src/cargo/sources/registry/mod.rs index 4cfe2005b46..ca19fc6c002 100644 --- a/src/cargo/sources/registry/mod.rs +++ b/src/cargo/sources/registry/mod.rs @@ -195,6 +195,7 @@ use std::task::{ready, Poll}; use anyhow::Context as _; use cargo_util::paths::{self, exclude_from_backups_and_indexing}; use flate2::read::GzDecoder; +use semver::VersionReq; use serde::Deserialize; use serde::Serialize; use tar::Archive; @@ -694,6 +695,10 @@ impl<'gctx> RegistrySource<'gctx> { .open(&path) .with_context(|| format!("failed to open `{}`", path.display()))?; + if let Err(e) = patch_extracted_package_if_needed(pkg, unpack_dir) { + tracing::warn!("error patching {pkg}: {e}"); + } + let lock_meta = LockMetadata { v: 1 }; write!(ok, "{}", serde_json::to_string(&lock_meta).unwrap())?; @@ -740,6 +745,28 @@ impl<'gctx> RegistrySource<'gctx> { } } +/// Workaround for in the `time` crate +fn patch_extracted_package_if_needed(pkg: PackageId, unpack_dir: &Path) -> CargoResult<()> { + if !pkg.source_id().is_crates_io() + || pkg.name() != "time" + || !VersionReq::parse("0.3.18,<0.3.35") + .unwrap() + .matches(pkg.version()) + { + return Ok(()); + } + + let patch_path = unpack_dir.join("src/format_description/parse/mod.rs"); + let source_code = std::fs::read_to_string(&patch_path)?; + + let patched = source_code.replace( + ", _>>", + ", _>>", + ); + std::fs::write(&patch_path, patched)?; + Ok(()) +} + impl<'gctx> Source for RegistrySource<'gctx> { fn query( &mut self,