@@ -195,6 +195,7 @@ use std::task::{ready, Poll};
195195use anyhow:: Context as _;
196196use cargo_util:: paths:: { self , exclude_from_backups_and_indexing} ;
197197use flate2:: read:: GzDecoder ;
198+ use semver:: VersionReq ;
198199use serde:: Deserialize ;
199200use serde:: Serialize ;
200201use 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+
743770impl < ' gctx > Source for RegistrySource < ' gctx > {
744771 fn query (
745772 & mut self ,
0 commit comments