diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index c378a4408c1..a6f144cb562 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1521,8 +1521,7 @@ impl TomlManifest { d.rev.take(); // registry specifications are elaborated to the index URL if let Some(registry) = d.registry.take() { - let src = SourceId::alt_registry(config, ®istry)?; - d.registry_index = Some(src.url().to_string()); + d.registry_index = Some(config.get_registry_index(®istry)?.to_string()); } Ok(TomlDependency::Detailed(d)) } diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index cec72d3184b..b4a896dff38 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -1337,3 +1337,51 @@ source = "sparse+http://[..]/" checksum = "f6a200a9339fef960979d94d5c99cbbfd899b6f5a396a55d9775089119050203""#, ); } + +#[cargo_test] +fn publish_with_transitive_dep() { + let _alt1 = RegistryBuilder::new() + .http_api() + .http_index() + .alternative_named("Alt-1") + .build(); + let _alt2 = RegistryBuilder::new() + .http_api() + .http_index() + .alternative_named("Alt-2") + .build(); + + let p1 = project() + .file( + "Cargo.toml", + r#" + [package] + name = "a" + version = "0.5.0" + "#, + ) + .file("src/lib.rs", "") + .build(); + p1.cargo("publish -Zsparse-registry --registry Alt-1") + .masquerade_as_nightly_cargo(&["sparse-registry"]) + .run(); + + let p2 = project() + .file( + "Cargo.toml", + r#" + [package] + name = "b" + version = "0.6.0" + publish = ["Alt-2"] + + [dependencies] + a = { version = "0.5.0", registry = "Alt-1" } + "#, + ) + .file("src/lib.rs", "") + .build(); + p2.cargo("publish -Zsparse-registry") + .masquerade_as_nightly_cargo(&["sparse-registry"]) + .run(); +}