Skip to content

Commit 000d279

Browse files
committed
Auto merge of #13125 - epage:public, r=weihanglo
fix(toml): Disallow inheriting of dependency public status ### What does this PR try to resolve? This is a step towards rust-lang/rust#44663. When discussing inheriting this field for #13046, we realized that we should probably start by disallowing inheritance. We can always add it later. imo the principle of what should be inherited is what is truely common among dependencies. For example, we don't allow removing features. Public should not be universally applied and likely should be explicit so its not over-done, especially since we can't (atm) lint for when a public dependency could be non-public. ### How should we test and review this PR? ### Additional information This reverts parts of #12817
2 parents 862e53a + 00557a2 commit 000d279

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

src/cargo/util/toml/mod.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ fn read_manifest_from_str(
118118
{
119119
for (name, dep) in deps {
120120
if dep.is_optional() {
121-
bail!(
122-
"{} is optional, but workspace dependencies cannot be optional",
123-
name
124-
);
121+
bail!("{name} is optional, but workspace dependencies cannot be optional",);
122+
}
123+
if dep.is_public() {
124+
bail!("{name} is public, but workspace dependencies cannot be public",);
125125
}
126126
}
127127
}
@@ -1667,11 +1667,6 @@ fn inner_dependency_inherit_with<'a>(
16671667
}
16681668
_ => {}
16691669
}
1670-
// Inherit the workspace configuration for `public` unless
1671-
// it's explicitly specified for this dependency.
1672-
if let Some(public) = dependency.public {
1673-
d.public = Some(public);
1674-
}
16751670
d.features = match (d.features.clone(), dependency.features.clone()) {
16761671
(Some(dep_feat), Some(inherit_feat)) => Some(
16771672
dep_feat

src/cargo/util_schemas/manifest.rs

+7
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,13 @@ impl TomlDependency {
534534
}
535535
}
536536

537+
pub fn is_public(&self) -> bool {
538+
match self {
539+
TomlDependency::Detailed(d) => d.public.unwrap_or(false),
540+
TomlDependency::Simple(..) => false,
541+
}
542+
}
543+
537544
pub fn unused_keys(&self) -> Vec<String> {
538545
match self {
539546
TomlDependency::Simple(_) => vec![],

src/doc/src/reference/unstable.md

+3
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ my_dep = { version = "1.2.3", public = true }
304304
private_dep = "2.0.0" # Will be 'private' by default
305305
```
306306

307+
Documentation updates:
308+
- For workspace's "The `dependencies` table" section, include `public` as an unsupported field for `workspace.dependencies`
309+
307310
## msrv-policy
308311
- [#9930](https://github.com/rust-lang/cargo/issues/9930) (MSRV-aware resolver)
309312
- [#10653](https://github.com/rust-lang/cargo/issues/10653) (MSRV-aware cargo-add)

tests/testsuite/pub_priv.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Caused by:
199199
}
200200

201201
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
202-
fn workspace_dep_made_public() {
202+
fn workspace_pub_disallowed() {
203203
Package::new("foo1", "0.1.0")
204204
.file("src/lib.rs", "pub struct FromFoo;")
205205
.publish();
@@ -244,5 +244,14 @@ fn workspace_dep_made_public() {
244244

245245
p.cargo("check")
246246
.masquerade_as_nightly_cargo(&["public-dependency"])
247+
.with_status(101)
248+
.with_stderr(
249+
"\
250+
error: failed to parse manifest at `[CWD]/Cargo.toml`
251+
252+
Caused by:
253+
foo2 is public, but workspace dependencies cannot be public
254+
",
255+
)
247256
.run()
248257
}

0 commit comments

Comments
 (0)