Skip to content

Commit c803297

Browse files
committed
Workaround for type inference breakage in the time crate
rust-lang/rust#127343
1 parent 3d2cf56 commit c803297

File tree

1 file changed

+27
-0
lines changed
  • src/cargo/sources/registry

1 file changed

+27
-0
lines changed

src/cargo/sources/registry/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ use std::task::{ready, Poll};
195195
use anyhow::Context as _;
196196
use cargo_util::paths::{self, exclude_from_backups_and_indexing};
197197
use flate2::read::GzDecoder;
198+
use semver::VersionReq;
198199
use serde::Deserialize;
199200
use serde::Serialize;
200201
use tar::Archive;
@@ -694,6 +695,10 @@ impl<'gctx> RegistrySource<'gctx> {
694695
.open(&path)
695696
.with_context(|| format!("failed to open `{}`", path.display()))?;
696697

698+
if let Err(e) = patch_extracted_package_if_needed(pkg, unpack_dir) {
699+
tracing::warn!("error patching {pkg}: {e}");
700+
}
701+
697702
let lock_meta = LockMetadata { v: 1 };
698703
write!(ok, "{}", serde_json::to_string(&lock_meta).unwrap())?;
699704

@@ -740,6 +745,28 @@ impl<'gctx> RegistrySource<'gctx> {
740745
}
741746
}
742747

748+
/// Workaround for <https://github.com/rust-lang/rust/issues/127343> in the `time` crate
749+
fn patch_extracted_package_if_needed(pkg: PackageId, unpack_dir: &Path) -> CargoResult<()> {
750+
if !pkg.source_id().is_crates_io()
751+
|| pkg.name() != "time"
752+
|| !VersionReq::parse("0.3.18,<0.3.35")
753+
.unwrap()
754+
.matches(pkg.version())
755+
{
756+
return Ok(());
757+
}
758+
759+
let patch_path = unpack_dir.join("src/format_description/parse/mod.rs");
760+
let source_code = std::fs::read_to_string(&patch_path)?;
761+
762+
let patched = source_code.replace(
763+
"<Result<Box<_>, _>>",
764+
"<Result<Box<[_ /*patched by Cargo*/ ]>, _>>",
765+
);
766+
std::fs::write(&patch_path, patched)?;
767+
Ok(())
768+
}
769+
743770
impl<'gctx> Source for RegistrySource<'gctx> {
744771
fn query(
745772
&mut self,

0 commit comments

Comments
 (0)