@@ -1171,20 +1171,32 @@ fn resolve_and_validate_dependencies(
11711171 let mut resolved = resolved;
11721172 if let manifest:: TomlDependency :: Detailed ( ref mut d) = resolved {
11731173 if d. public . is_some ( ) {
1174+ let public_feature = manifest_ctx. features . require ( Feature :: public_dependency ( ) ) ;
1175+ let with_public_feature = public_feature. is_ok ( ) ;
1176+ let with_z_public = manifest_ctx. gctx . cli_unstable ( ) . public_dependency ;
1177+ if !with_public_feature
1178+ && ( !with_z_public && !manifest_ctx. gctx . nightly_features_allowed )
1179+ {
1180+ public_feature?;
1181+ }
11741182 if matches ! ( kind, None ) {
1175- if !manifest_ctx
1176- . features
1177- . require ( Feature :: public_dependency ( ) )
1178- . is_ok ( )
1179- && !manifest_ctx. gctx . cli_unstable ( ) . public_dependency
1180- {
1183+ if !with_public_feature && !with_z_public {
11811184 d. public = None ;
11821185 manifest_ctx. warnings . push ( format ! (
11831186 "ignoring `public` on dependency {name_in_toml}, pass `-Zpublic-dependency` to enable support for it"
11841187 ) )
11851188 }
11861189 } else {
1187- d. public = None ;
1190+ let hint = format ! (
1191+ "'public' specifier can only be used on regular dependencies, not {kind_name}" ,
1192+ ) ;
1193+ if with_public_feature || with_z_public {
1194+ bail ! ( hint)
1195+ } else {
1196+ // If public feature isn't enabled in nightly, we instead warn that.
1197+ manifest_ctx. warnings . push ( hint) ;
1198+ d. public = None ;
1199+ }
11881200 }
11891201 }
11901202 }
@@ -2131,26 +2143,7 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
21312143 }
21322144
21332145 if let Some ( p) = orig. public {
2134- let public_feature = manifest_ctx. features . require ( Feature :: public_dependency ( ) ) ;
2135- let with_z_public = manifest_ctx. gctx . cli_unstable ( ) . public_dependency ;
2136- let with_public_feature = public_feature. is_ok ( ) ;
2137- if !with_public_feature && ( !with_z_public && !manifest_ctx. gctx . nightly_features_allowed ) {
2138- public_feature?;
2139- }
2140-
2141- if dep. kind ( ) != DepKind :: Normal {
2142- let hint = format ! (
2143- "'public' specifier can only be used on regular dependencies, not {}" ,
2144- dep. kind( ) . kind_table( ) ,
2145- ) ;
2146- match ( with_public_feature, with_z_public) {
2147- ( true , _) | ( _, true ) => bail ! ( hint) ,
2148- // If public feature isn't enabled in nightly, we instead warn that.
2149- ( false , false ) => manifest_ctx. warnings . push ( hint) ,
2150- }
2151- } else {
2152- dep. set_public ( p) ;
2153- }
2146+ dep. set_public ( p) ;
21542147 }
21552148
21562149 if let ( Some ( artifact) , is_lib, target) = (
0 commit comments