@@ -65,6 +65,31 @@ pub fn read_manifest(
6565 path : & Path ,
6666 source_id : SourceId ,
6767 gctx : & GlobalContext ,
68+ ) -> CargoResult < EitherManifest > {
69+ read_manifest_impl ( path, source_id, gctx, false )
70+ }
71+
72+ /// Loads a cargo-generated `Cargo.toml` from a file on disk.
73+ ///
74+ /// This is for reading manifests that were generated by cargo itself
75+ /// (e.g., during package verification), which may contain internal-only
76+ /// fields like `registry-index`.
77+ #[ tracing:: instrument( skip( gctx) ) ]
78+ pub fn read_cargo_generated_manifest (
79+ path : & Path ,
80+ source_id : SourceId ,
81+ gctx : & GlobalContext ,
82+ ) -> CargoResult < EitherManifest > {
83+ read_manifest_impl ( path, source_id, gctx, true )
84+ }
85+
86+ /// Internal implementation with cargo_generated parameter
87+ #[ tracing:: instrument( skip( gctx) ) ]
88+ fn read_manifest_impl (
89+ path : & Path ,
90+ source_id : SourceId ,
91+ gctx : & GlobalContext ,
92+ cargo_generated : bool ,
6893) -> CargoResult < EitherManifest > {
6994 let mut warnings = Default :: default ( ) ;
7095 let mut errors = Default :: default ( ) ;
@@ -99,7 +124,7 @@ pub fn read_manifest(
99124 ) ?;
100125
101126 if normalized_toml. package ( ) . is_some ( ) {
102- to_real_manifest (
127+ to_real_manifest_impl (
103128 contents,
104129 document,
105130 original_toml,
@@ -109,6 +134,7 @@ pub fn read_manifest(
109134 source_id,
110135 path,
111136 is_embedded,
137+ cargo_generated,
112138 gctx,
113139 & mut warnings,
114140 & mut errors,
@@ -1276,6 +1302,40 @@ pub fn to_real_manifest(
12761302 gctx : & GlobalContext ,
12771303 warnings : & mut Vec < String > ,
12781304 _errors : & mut Vec < String > ,
1305+ ) -> CargoResult < Manifest > {
1306+ to_real_manifest_impl (
1307+ contents,
1308+ document,
1309+ original_toml,
1310+ normalized_toml,
1311+ features,
1312+ workspace_config,
1313+ source_id,
1314+ manifest_file,
1315+ is_embedded,
1316+ false ,
1317+ gctx,
1318+ warnings,
1319+ _errors,
1320+ )
1321+ }
1322+
1323+ /// Internal implementation with cargo_generated parameter
1324+ #[ tracing:: instrument( skip_all) ]
1325+ fn to_real_manifest_impl (
1326+ contents : String ,
1327+ document : toml:: Spanned < toml:: de:: DeTable < ' static > > ,
1328+ original_toml : manifest:: TomlManifest ,
1329+ normalized_toml : manifest:: TomlManifest ,
1330+ features : Features ,
1331+ workspace_config : WorkspaceConfig ,
1332+ source_id : SourceId ,
1333+ manifest_file : & Path ,
1334+ is_embedded : bool ,
1335+ cargo_generated : bool ,
1336+ gctx : & GlobalContext ,
1337+ warnings : & mut Vec < String > ,
1338+ _errors : & mut Vec < String > ,
12791339) -> CargoResult < Manifest > {
12801340 let package_root = manifest_file. parent ( ) . unwrap ( ) ;
12811341 if !package_root. is_dir ( ) {
@@ -1582,6 +1642,7 @@ pub fn to_real_manifest(
15821642 warnings,
15831643 platform : None ,
15841644 root : package_root,
1645+ cargo_generated,
15851646 } ;
15861647 gather_dependencies (
15871648 & mut manifest_ctx,
@@ -1977,6 +2038,7 @@ fn to_virtual_manifest(
19772038 warnings,
19782039 platform : None ,
19792040 root,
2041+ cargo_generated : false ,
19802042 } ;
19812043 (
19822044 replace ( & normalized_toml, & mut manifest_ctx) ?,
@@ -2045,6 +2107,7 @@ struct ManifestContext<'a, 'b> {
20452107 warnings : & ' a mut Vec < String > ,
20462108 platform : Option < Platform > ,
20472109 root : & ' a Path ,
2110+ cargo_generated : bool ,
20482111}
20492112
20502113#[ tracing:: instrument( skip_all) ]
@@ -2175,6 +2238,7 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
21752238 warnings,
21762239 platform,
21772240 root,
2241+ cargo_generated : false ,
21782242 } ,
21792243 kind,
21802244 )
@@ -2292,6 +2356,19 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
22922356 dep. set_registry_id ( registry_id) ;
22932357 }
22942358 if let Some ( registry_index) = & orig. registry_index {
2359+ // `registry-index` is for internal use only.
2360+ // It should not be used in user-written manifests as it bypasses the need for .cargo/config.toml configuration.
2361+
2362+ if !manifest_ctx. source_id . is_registry ( )
2363+ && !manifest_ctx. source_id . is_directory ( )
2364+ && !manifest_ctx. cargo_generated
2365+ {
2366+ bail ! (
2367+ "dependency ({}) specification uses `registry-index` which is for internal use only\n \
2368+ help: use `registry = \" <name>\" ` and configure the registry in `.cargo/config.toml`",
2369+ name_in_toml
2370+ ) ;
2371+ }
22952372 let url = registry_index. into_url ( ) ?;
22962373 let registry_id = SourceId :: for_registry ( & url) ?;
22972374 dep. set_registry_id ( registry_id) ;
@@ -2936,7 +3013,8 @@ pub fn prepare_for_publish(
29363013 let mut warnings = Default :: default ( ) ;
29373014 let mut errors = Default :: default ( ) ;
29383015 let gctx = ws. gctx ( ) ;
2939- let manifest = to_real_manifest (
3016+ let cargo_generated = true ;
3017+ let manifest = to_real_manifest_impl (
29403018 contents. to_owned ( ) ,
29413019 document. clone ( ) ,
29423020 original_toml,
@@ -2946,6 +3024,7 @@ pub fn prepare_for_publish(
29463024 source_id,
29473025 me. manifest_path ( ) ,
29483026 me. manifest ( ) . is_embedded ( ) ,
3027+ cargo_generated,
29493028 gctx,
29503029 & mut warnings,
29513030 & mut errors,
0 commit comments