@@ -9,8 +9,8 @@ use crate::AlreadyPrintedError;
9
9
use anyhow:: { anyhow, bail, Context as _} ;
10
10
use cargo_platform:: Platform ;
11
11
use cargo_util:: paths;
12
- use cargo_util_schemas:: manifest;
13
12
use cargo_util_schemas:: manifest:: RustVersion ;
13
+ use cargo_util_schemas:: manifest:: { self , InheritableDependency , TomlDependency } ;
14
14
use itertools:: Itertools ;
15
15
use lazycell:: LazyCell ;
16
16
use pathdiff:: diff_paths;
@@ -104,13 +104,30 @@ fn read_manifest_from_str(
104
104
let package_root = manifest_file. parent ( ) . unwrap ( ) ;
105
105
106
106
let mut unused = BTreeSet :: new ( ) ;
107
+ let mut public_deps_without_z = BTreeSet :: new ( ) ;
108
+
107
109
let deserializer = toml:: de:: Deserializer :: new ( contents) ;
108
110
let manifest: manifest:: TomlManifest = match serde_ignored:: deserialize ( deserializer, |path| {
109
111
let mut key = String :: new ( ) ;
110
112
stringify ( & mut key, & path) ;
111
113
unused. insert ( key) ;
112
114
} ) {
113
- Ok ( manifest) => manifest,
115
+ Ok ( manifest) => {
116
+ let mut manifest: manifest:: TomlManifest = manifest;
117
+ if let Some ( deps) = & mut manifest. dependencies {
118
+ for ( name, dep) in deps {
119
+ if let InheritableDependency :: Value ( toml_dep) = dep {
120
+ if let TomlDependency :: Detailed ( d) = toml_dep {
121
+ if !config. cli_unstable ( ) . public_dependency && d. public . is_some ( ) {
122
+ d. public = None ;
123
+ public_deps_without_z. insert ( name. clone ( ) ) ;
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+ manifest
130
+ }
114
131
Err ( e) => {
115
132
let Some ( span) = e. span ( ) else {
116
133
return Err ( e. into ( ) ) ;
@@ -168,6 +185,13 @@ fn read_manifest_from_str(
168
185
}
169
186
}
170
187
} ;
188
+ let public_warn = |warnings : & mut Warnings | {
189
+ for name in public_deps_without_z {
190
+ warnings. add_warning ( format ! (
191
+ "{name} uses 'public' specifier, pass `-Zpublic-dependency` to enable support for it" ,
192
+ ) )
193
+ }
194
+ } ;
171
195
172
196
if let Some ( deps) = manifest
173
197
. workspace
@@ -187,6 +211,7 @@ fn read_manifest_from_str(
187
211
let ( mut manifest, paths) =
188
212
to_real_manifest ( manifest, embedded, source_id, package_root, config) ?;
189
213
add_unused ( manifest. warnings_mut ( ) ) ;
214
+ public_warn ( manifest. warnings_mut ( ) ) ;
190
215
if manifest. targets ( ) . iter ( ) . all ( |t| t. is_custom_build ( ) ) {
191
216
bail ! (
192
217
"no targets specified in the manifest\n \
@@ -198,6 +223,7 @@ fn read_manifest_from_str(
198
223
} else {
199
224
let ( mut m, paths) = to_virtual_manifest ( manifest, source_id, package_root, config) ?;
200
225
add_unused ( m. warnings_mut ( ) ) ;
226
+ public_warn ( m. warnings_mut ( ) ) ;
201
227
Ok ( ( EitherManifest :: Virtual ( m) , paths) )
202
228
} ;
203
229
@@ -678,7 +704,6 @@ pub fn to_real_manifest(
678
704
nested_paths : & mut nested_paths,
679
705
config,
680
706
warnings : & mut warnings,
681
- features : & features,
682
707
platform : None ,
683
708
root : package_root,
684
709
} ;
@@ -1153,7 +1178,6 @@ fn to_virtual_manifest(
1153
1178
config,
1154
1179
warnings : & mut warnings,
1155
1180
platform : None ,
1156
- features : & features,
1157
1181
root,
1158
1182
} ;
1159
1183
( replace ( & me, & mut cx) ?, patch ( & me, & mut cx) ?)
@@ -1302,7 +1326,6 @@ struct Context<'a, 'b> {
1302
1326
warnings : & ' a mut Vec < String > ,
1303
1327
platform : Option < Platform > ,
1304
1328
root : & ' a Path ,
1305
- features : & ' a Features ,
1306
1329
}
1307
1330
1308
1331
fn verify_lints ( lints : Option < manifest:: TomlLints > ) -> CargoResult < Option < manifest:: TomlLints > > {
@@ -1709,7 +1732,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
1709
1732
warnings : & mut Vec < String > ,
1710
1733
platform : Option < Platform > ,
1711
1734
root : & Path ,
1712
- features : & Features ,
1713
1735
kind : Option < DepKind > ,
1714
1736
) -> CargoResult < Dependency > {
1715
1737
dep_to_dependency (
@@ -1723,7 +1745,6 @@ pub(crate) fn to_dependency<P: ResolveToPath + Clone>(
1723
1745
warnings,
1724
1746
platform,
1725
1747
root,
1726
- features,
1727
1748
} ,
1728
1749
kind,
1729
1750
)
@@ -1944,7 +1965,17 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
1944
1965
}
1945
1966
1946
1967
if let Some ( p) = orig. public {
1947
- cx. features . require ( Feature :: public_dependency ( ) ) ?;
1968
+ if !cx. config . nightly_features_allowed {
1969
+ bail ! (
1970
+ "Consider trying a newer version of Cargo (this may require the nightly release)."
1971
+ ) ;
1972
+ }
1973
+ if !cx. config . cli_unstable ( ) . public_dependency {
1974
+ bail ! ( format!(
1975
+ "{name} uses 'public' specifier, pass `-Zpublic-dependency` to enable support for it" ,
1976
+ name = dep. name_in_toml( ) ,
1977
+ ) ) ;
1978
+ }
1948
1979
1949
1980
if dep. kind ( ) != DepKind :: Normal {
1950
1981
bail ! ( "'public' specifier can only be used on regular dependencies, not {:?} dependencies" , dep. kind( ) ) ;
0 commit comments