@@ -1276,6 +1276,40 @@ pub fn to_real_manifest(
12761276 gctx : & GlobalContext ,
12771277 warnings : & mut Vec < String > ,
12781278 _errors : & mut Vec < String > ,
1279+ ) -> CargoResult < Manifest > {
1280+ to_real_manifest_impl (
1281+ contents,
1282+ document,
1283+ original_toml,
1284+ normalized_toml,
1285+ features,
1286+ workspace_config,
1287+ source_id,
1288+ manifest_file,
1289+ is_embedded,
1290+ gctx,
1291+ warnings,
1292+ _errors,
1293+ false ,
1294+ )
1295+ }
1296+
1297+ /// Internal implementation with cargo_generated parameter
1298+ #[ tracing:: instrument( skip_all) ]
1299+ fn to_real_manifest_impl (
1300+ contents : String ,
1301+ document : toml:: Spanned < toml:: de:: DeTable < ' static > > ,
1302+ original_toml : manifest:: TomlManifest ,
1303+ normalized_toml : manifest:: TomlManifest ,
1304+ features : Features ,
1305+ workspace_config : WorkspaceConfig ,
1306+ source_id : SourceId ,
1307+ manifest_file : & Path ,
1308+ is_embedded : bool ,
1309+ gctx : & GlobalContext ,
1310+ warnings : & mut Vec < String > ,
1311+ _errors : & mut Vec < String > ,
1312+ cargo_generated : bool ,
12791313) -> CargoResult < Manifest > {
12801314 let package_root = manifest_file. parent ( ) . unwrap ( ) ;
12811315 if !package_root. is_dir ( ) {
@@ -1582,6 +1616,7 @@ pub fn to_real_manifest(
15821616 warnings,
15831617 platform : None ,
15841618 root : package_root,
1619+ cargo_generated,
15851620 } ;
15861621 gather_dependencies (
15871622 & mut manifest_ctx,
@@ -1977,6 +2012,7 @@ fn to_virtual_manifest(
19772012 warnings,
19782013 platform : None ,
19792014 root,
2015+ cargo_generated : false ,
19802016 } ;
19812017 (
19822018 replace ( & normalized_toml, & mut manifest_ctx) ?,
@@ -2045,6 +2081,7 @@ struct ManifestContext<'a, 'b> {
20452081 warnings : & ' a mut Vec < String > ,
20462082 platform : Option < Platform > ,
20472083 root : & ' a Path ,
2084+ cargo_generated : bool ,
20482085}
20492086
20502087#[ tracing:: instrument( skip_all) ]
@@ -2175,6 +2212,7 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
21752212 warnings,
21762213 platform,
21772214 root,
2215+ cargo_generated : false ,
21782216 } ,
21792217 kind,
21802218 )
@@ -2292,6 +2330,24 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
22922330 dep. set_registry_id ( registry_id) ;
22932331 }
22942332 if let Some ( registry_index) = & orig. registry_index {
2333+ // `registry-index` is for internal use only.
2334+ // It should not be used in user-written manifests as it bypasses the need for .cargo/config.toml configuration.
2335+
2336+ if !manifest_ctx. source_id . is_registry ( ) && !manifest_ctx. cargo_generated {
2337+ // Check if this is a packaged manifest (in target/package or target\package)
2338+ // by checking if the path contains the pattern
2339+ let path_str = manifest_ctx. root . to_string_lossy ( ) ;
2340+ let is_packaged_manifest =
2341+ path_str. contains ( "target/package" ) || path_str. contains ( "target\\ package" ) ;
2342+
2343+ if !is_packaged_manifest {
2344+ bail ! (
2345+ "dependency ({}) specification uses `registry-index` which is for internal use only\n \
2346+ help: use `registry = \" <name>\" ` and configure the registry in `.cargo/config.toml`",
2347+ name_in_toml
2348+ ) ;
2349+ }
2350+ }
22952351 let url = registry_index. into_url ( ) ?;
22962352 let registry_id = SourceId :: for_registry ( & url) ?;
22972353 dep. set_registry_id ( registry_id) ;
@@ -2936,7 +2992,7 @@ pub fn prepare_for_publish(
29362992 let mut warnings = Default :: default ( ) ;
29372993 let mut errors = Default :: default ( ) ;
29382994 let gctx = ws. gctx ( ) ;
2939- let manifest = to_real_manifest (
2995+ let manifest = to_real_manifest_impl (
29402996 contents. to_owned ( ) ,
29412997 document. clone ( ) ,
29422998 original_toml,
@@ -2949,6 +3005,7 @@ pub fn prepare_for_publish(
29493005 gctx,
29503006 & mut warnings,
29513007 & mut errors,
3008+ true , // cargo_generated - this is a Cargo-generated manifest
29523009 ) ?;
29533010 let new_pkg = Package :: new ( manifest, me. manifest_path ( ) ) ;
29543011 Ok ( new_pkg)
0 commit comments