Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Add doc for -Zpublic-dependency #13556

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ pub fn to_real_manifest(
{
d.public = None;
manifest_ctx.warnings.push(format!(
"Ignoring `public` on dependency {name}. Pass `-Zpublic-dependency` to enable support for it", name = &dep.name_in_toml()
"ignoring `public` on dependency {name}, pass `-Zpublic-dependency` to enable support for it", name = &dep.name_in_toml()
))
}
} else {
Expand Down Expand Up @@ -2062,11 +2062,14 @@ fn detailed_dep_to_dependency<P: ResolveToPath + Clone>(
}

if dep.kind() != DepKind::Normal {
let hint = format!(
"'public' specifier can only be used on regular dependencies, not {}",
dep.kind().kind_table(),
);
match (with_public_feature, with_z_public) {
(true, _) => bail!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind()),
(_, true) => bail!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind()),
(true, _) | (_, true) => bail!(hint),
// If public feature isn't enabled in nightly, we instead warn that.
(false, false) => manifest_ctx.warnings.push(format!("'public' specifier can only be used on regular dependencies, not {:?} dependencies", dep.kind())),
(false, false) => manifest_ctx.warnings.push(hint),
}
} else {
dep.set_public(p);
Expand Down
16 changes: 15 additions & 1 deletion src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,21 @@ The 'public-dependency' feature allows marking dependencies as 'public'
or 'private'. When this feature is enabled, additional information is passed to rustc to allow
the 'exported_private_dependencies' lint to function properly.

This requires the appropriate key to be set in `cargo-features`:
To enable this feature, you can either use `-Zpublic-dependency`

```sh
cargo +nightly run -Zpublic-dependency
```

or `[unstable]` table, for example,

```toml
# .cargo/config.toml
[unstable]
public-dependency = true
```

`public-dependency` could also be enabled in `cargo-features`, **though this is deprecated and will be removed soon**.

```toml
cargo-features = ["public-dependency"]
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/pub_priv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn requires_feature() {
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_stderr(
"\
[WARNING] Ignoring `public` on dependency pub_dep. Pass `-Zpublic-dependency` to enable support for it
[WARNING] ignoring `public` on dependency pub_dep, pass `-Zpublic-dependency` to enable support for it
[UPDATING] `[..]` index
[DOWNLOADING] crates ...
[DOWNLOADED] pub_dep v0.1.0 ([..])
Expand Down Expand Up @@ -191,7 +191,7 @@ fn pub_dev_dependency() {
error: failed to parse manifest at `[..]`

Caused by:
'public' specifier can only be used on regular dependencies, not Development dependencies
'public' specifier can only be used on regular dependencies, not dev-dependencies
",
)
.run()
Expand Down Expand Up @@ -229,7 +229,7 @@ fn pub_dev_dependency_without_feature() {
.masquerade_as_nightly_cargo(&["public-dependency"])
.with_stderr(
"\
[WARNING] 'public' specifier can only be used on regular dependencies, not Development dependencies
[WARNING] 'public' specifier can only be used on regular dependencies, not dev-dependencies
[UPDATING] `[..]` index
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
",
Expand Down