Skip to content

Commit 00557a2

Browse files
committed
fix(toml): Disallow inheriting of dependency public status
This is a step towards #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. This reverts parts of #12817
1 parent 123289b commit 00557a2

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ fn read_manifest_from_str(
120120
if dep.is_optional() {
121121
bail!("{name} is optional, but workspace dependencies cannot be optional",);
122122
}
123+
if dep.is_public() {
124+
bail!("{name} is public, but workspace dependencies cannot be public",);
125+
}
123126
}
124127
}
125128
return if manifest.project.is_some() || manifest.package.is_some() {
@@ -1664,11 +1667,6 @@ fn inner_dependency_inherit_with<'a>(
16641667
}
16651668
_ => {}
16661669
}
1667-
// Inherit the workspace configuration for `public` unless
1668-
// it's explicitly specified for this dependency.
1669-
if let Some(public) = dependency.public {
1670-
d.public = Some(public);
1671-
}
16721670
d.features = match (d.features.clone(), dependency.features.clone()) {
16731671
(Some(dep_feat), Some(inherit_feat)) => Some(
16741672
dep_feat

src/cargo/util_schemas/manifest.rs

Lines changed: 7 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 10 additions & 1 deletion
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)