Skip to content

Commit ce3d32a

Browse files
committed
Auto merge of #13556 - linyihai:doc-z-public, r=weihanglo
doc: Add doc for -Zpublic-dependency ### What does this PR try to resolve? - add doc for -Zpublic-dependency - optimize log display about -Zpublic-dependency ### How should we test and review this PR? ### Additional information
2 parents 5c24f04 + 759c3ad commit ce3d32a

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ pub fn to_real_manifest(
779779
{
780780
d.public = None;
781781
manifest_ctx.warnings.push(format!(
782-
"Ignoring `public` on dependency {name}. Pass `-Zpublic-dependency` to enable support for it", name = &dep.name_in_toml()
782+
"ignoring `public` on dependency {name}, pass `-Zpublic-dependency` to enable support for it", name = &dep.name_in_toml()
783783
))
784784
}
785785
} else {
@@ -2062,11 +2062,14 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
20622062
}
20632063

20642064
if dep.kind() != DepKind::Normal {
2065+
let hint = format!(
2066+
"'public' specifier can only be used on regular dependencies, not {}",
2067+
dep.kind().kind_table(),
2068+
);
20652069
match (with_public_feature, with_z_public) {
2066-
(true, _) => bail!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind()),
2067-
(_, true) => bail!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind()),
2070+
(true, _) | (_, true) => bail!(hint),
20682071
// If public feature isn't enabled in nightly, we instead warn that.
2069-
(false, false) => manifest_ctx.warnings.push(format!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind())),
2072+
(false, false) => manifest_ctx.warnings.push(hint),
20702073
}
20712074
} else {
20722075
dep.set_public(p);

src/doc/src/reference/unstable.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,21 @@ The 'public-dependency' feature allows marking dependencies as 'public'
296296
or 'private'. When this feature is enabled, additional information is passed to rustc to allow
297297
the [exported_private_dependencies](../../rustc/lints/listing/warn-by-default.html#exported-private-dependencies) lint to function properly.
298298

299-
This requires the appropriate key to be set in `cargo-features`:
299+
To enable this feature, you can either use `-Zpublic-dependency`
300+
301+
```sh
302+
cargo +nightly run -Zpublic-dependency
303+
```
304+
305+
or `[unstable]` table, for example,
306+
307+
```toml
308+
# .cargo/config.toml
309+
[unstable]
310+
public-dependency = true
311+
```
312+
313+
`public-dependency` could also be enabled in `cargo-features`, **though this is deprecated and will be removed soon**.
300314

301315
```toml
302316
cargo-features = ["public-dependency"]

tests/testsuite/pub_priv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ fn requires_feature() {
141141
.masquerade_as_nightly_cargo(&["public-dependency"])
142142
.with_stderr(
143143
"\
144-
[WARNING] Ignoring `public` on dependency pub_dep. Pass `-Zpublic-dependency` to enable support for it
144+
[WARNING] ignoring `public` on dependency pub_dep, pass `-Zpublic-dependency` to enable support for it
145145
[UPDATING] `[..]` index
146146
[DOWNLOADING] crates ...
147147
[DOWNLOADED] pub_dep v0.1.0 ([..])
@@ -191,7 +191,7 @@ fn pub_dev_dependency() {
191191
error: failed to parse manifest at `[..]`
192192
193193
Caused by:
194-
'public' specifier can only be used on regular dependencies, not Development dependencies
194+
'public' specifier can only be used on regular dependencies, not dev-dependencies
195195
",
196196
)
197197
.run()
@@ -229,7 +229,7 @@ fn pub_dev_dependency_without_feature() {
229229
.masquerade_as_nightly_cargo(&["public-dependency"])
230230
.with_stderr(
231231
"\
232-
[WARNING] 'public' specifier can only be used on regular dependencies, not Development dependencies
232+
[WARNING] 'public' specifier can only be used on regular dependencies, not dev-dependencies
233233
[UPDATING] `[..]` index
234234
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
235235
",

0 commit comments

Comments
 (0)