From 60141ec232ee2a042c9cdbfde50bbbd17650c408 Mon Sep 17 00:00:00 2001 From: Simon Thornington Date: Sun, 20 Oct 2024 15:52:25 -0400 Subject: [PATCH] =?UTF-8?q?add=20a=20Source::parse=20arm=20for=20sparse=20?= =?UTF-8?q?repos=20(keeping=20it=20in=20the=20scheme).=20=E2=80=A6=20(#295?= =?UTF-8?q?0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Proc macro resolution wasn't working properly for sparse repos. This fixes #2938. --------- Co-authored-by: Daniel Wagner-Hall Co-authored-by: Daniel Wagner-Hall --- .../src/metadata/cargo_tree_resolver.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crate_universe/src/metadata/cargo_tree_resolver.rs b/crate_universe/src/metadata/cargo_tree_resolver.rs index 20cacc5390..2b111ddfd3 100644 --- a/crate_universe/src/metadata/cargo_tree_resolver.rs +++ b/crate_universe/src/metadata/cargo_tree_resolver.rs @@ -581,6 +581,11 @@ impl Source { let original_scheme = url.scheme().to_owned(); let scheme_parts: Vec<_> = original_scheme.split('+').collect(); match &scheme_parts[..] { + // e.g. sparse+https://github.com/rust-lang/crates.io-index + ["sparse", _] => Ok(Self::Registry { + registry: url.to_string(), + version, + }), // e.g. registry+https://github.com/rust-lang/crates.io-index ["registry", scheme] => { let new_url = set_url_scheme_despite_the_url_crate_not_wanting_us_to(&url, scheme)?; @@ -936,6 +941,25 @@ mod test { use super::*; + #[test] + fn parse_sparse_source() { + let source = Source::parse( + "sparse+https://github.com/rust-lang/crates.io-index", + "1.0.1".to_owned(), + ) + .unwrap(); + // sparse we want to leave the augmented scheme in there. + // cargo_toml::DependencyDetail::registry_index explicitly supports + // sparse+https: + assert_eq!( + source, + Source::Registry { + registry: "sparse+https://github.com/rust-lang/crates.io-index".to_owned(), + version: "1.0.1".to_owned() + } + ); + } + #[test] fn parse_registry_source() { let source = Source::parse(