Skip to content

Commit 756fc40

Browse files
committed
Support public dependency configuration with workspace deps
This commit updates the processing of `workspace = true` dependencies in the `[dependencies]` section to process the `public` field. Previously this field was ignored and didn't get plumbed through as configured.
1 parent eb2b3f9 commit 756fc40

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,7 @@ pub struct TomlWorkspaceDependency {
20802080
#[serde(rename = "default_features")]
20812081
default_features2: Option<bool>,
20822082
optional: Option<bool>,
2083+
public: Option<bool>,
20832084
/// This is here to provide a way to see the "unused manifest keys" when deserializing
20842085
#[serde(skip_serializing)]
20852086
#[serde(flatten)]
@@ -2114,11 +2115,12 @@ impl TomlWorkspaceDependency {
21142115
if let Some(false) = self.default_features.or(self.default_features2) {
21152116
default_features_msg(name, None, cx);
21162117
}
2117-
if self.optional.is_some() || self.features.is_some() {
2118+
if self.optional.is_some() || self.features.is_some() || self.public.is_some() {
21182119
TomlDependency::Detailed(DetailedTomlDependency {
21192120
version: Some(s),
21202121
optional: self.optional,
21212122
features: self.features.clone(),
2123+
public: self.public,
21222124
..Default::default()
21232125
})
21242126
} else {
@@ -2150,6 +2152,11 @@ impl TomlWorkspaceDependency {
21502152
}
21512153
_ => {}
21522154
}
2155+
// Inherit the workspace configuration for `public` unless
2156+
// it's explicitly specified for this dependency.
2157+
if let Some(public) = self.public {
2158+
d.public = Some(public);
2159+
}
21532160
d.add_features(self.features.clone());
21542161
d.update_optional(self.optional);
21552162
TomlDependency::Detailed(d)

tests/testsuite/pub_priv.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,52 @@ Caused by:
197197
)
198198
.run()
199199
}
200+
201+
#[cargo_test(nightly, reason = "exported_private_dependencies lint is unstable")]
202+
fn workspace_dep_made_public() {
203+
Package::new("foo1", "0.1.0")
204+
.file("src/lib.rs", "pub struct FromFoo;")
205+
.publish();
206+
Package::new("foo2", "0.1.0")
207+
.file("src/lib.rs", "pub struct FromFoo;")
208+
.publish();
209+
Package::new("foo3", "0.1.0")
210+
.file("src/lib.rs", "pub struct FromFoo;")
211+
.publish();
212+
213+
let p = project()
214+
.file(
215+
"Cargo.toml",
216+
r#"
217+
cargo-features = ["public-dependency"]
218+
219+
[package]
220+
name = "foo"
221+
version = "0.0.1"
222+
223+
[workspace.dependencies]
224+
foo1 = "0.1.0"
225+
foo2 = { version = "0.1.0", public = true }
226+
foo3 = { version = "0.1.0", public = false }
227+
228+
[dependencies]
229+
foo1 = { workspace = true, public = true }
230+
foo2 = { workspace = true }
231+
foo3 = { workspace = true, public = true }
232+
"#,
233+
)
234+
.file(
235+
"src/lib.rs",
236+
"
237+
#![deny(exported_private_dependencies)]
238+
pub fn use_priv1(_: foo1::FromFoo) {}
239+
pub fn use_priv2(_: foo2::FromFoo) {}
240+
pub fn use_priv3(_: foo3::FromFoo) {}
241+
",
242+
)
243+
.build();
244+
245+
p.cargo("check")
246+
.masquerade_as_nightly_cargo(&["public-dependency"])
247+
.run()
248+
}

0 commit comments

Comments
 (0)