@@ -201,6 +201,12 @@ impl<'de> de::Deserialize<'de> for TomlDependency {
201201pub struct DetailedTomlDependency {
202202 version : Option < String > ,
203203 registry : Option < String > ,
204+ /// The URL of the `registry` field.
205+ /// This is an internal implementation detail. When Cargo creates a
206+ /// package, it replaces `registry` with `registry-index` so that the
207+ /// manifest contains the correct URL. All users won't have the same
208+ /// registry names configured, so Cargo can't rely on just the name for
209+ /// crates published by other users.
204210 registry_index : Option < String > ,
205211 path : Option < String > ,
206212 git : Option < String > ,
@@ -1307,14 +1313,6 @@ impl DetailedTomlDependency {
13071313 }
13081314 }
13091315
1310- let registry_id = match self . registry {
1311- Some ( ref registry) => {
1312- cx. features . require ( Feature :: alternative_registries ( ) ) ?;
1313- SourceId :: alt_registry ( cx. config , registry) ?
1314- }
1315- None => SourceId :: crates_io ( cx. config ) ?,
1316- } ;
1317-
13181316 let new_source_id = match (
13191317 self . git . as_ref ( ) ,
13201318 self . path . as_ref ( ) ,
@@ -1410,8 +1408,19 @@ impl DetailedTomlDependency {
14101408 . unwrap_or ( true ) ,
14111409 )
14121410 . set_optional ( self . optional . unwrap_or ( false ) )
1413- . set_platform ( cx. platform . clone ( ) )
1414- . set_registry_id ( registry_id) ;
1411+ . set_platform ( cx. platform . clone ( ) ) ;
1412+ if let Some ( registry) = & self . registry {
1413+ cx. features . require ( Feature :: alternative_registries ( ) ) ?;
1414+ let registry_id = SourceId :: alt_registry ( cx. config , registry) ?;
1415+ dep. set_registry_id ( registry_id) ;
1416+ }
1417+ if let Some ( registry_index) = & self . registry_index {
1418+ cx. features . require ( Feature :: alternative_registries ( ) ) ?;
1419+ let url = registry_index. to_url ( ) ?;
1420+ let registry_id = SourceId :: for_registry ( & url) ?;
1421+ dep. set_registry_id ( registry_id) ;
1422+ }
1423+
14151424 if let Some ( kind) = kind {
14161425 dep. set_kind ( kind) ;
14171426 }
0 commit comments