Skip to content

Commit

Permalink
chore: Optimize log display about -Zpublic-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Mar 7, 2024
1 parent 2ff7cc3 commit 759c3ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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
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

0 comments on commit 759c3ad

Please sign in to comment.