Skip to content

Commit 961c442

Browse files
committed
fix(toml): Disallow inheriting of dependency public status
This is a step towards #44663. When discussing inheriting this field for rust-lang#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 rust-lang#12817
1 parent 123289b commit 961c442

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
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)

0 commit comments

Comments
 (0)