Skip to content

Commit 1eafdb2

Browse files
committed
fix(publish): Report all unpublishable packages
I didn't extend this to multiple packages restricted to specific registries. It seems less likely to be a problem and more complex to gather and report. This was inspired by feedback left at #10948
1 parent a282233 commit 1eafdb2

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/cargo/ops/registry/publish.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,17 @@ fn package_list(pkgs: impl IntoIterator<Item = PackageId>, final_sep: &str) -> S
703703
}
704704

705705
fn validate_registry(pkgs: &[&Package], reg_or_index: Option<&RegistryOrIndex>) -> CargoResult<()> {
706-
for pkg in pkgs {
707-
if pkg.publish() == &Some(Vec::new()) {
708-
bail!(
709-
"`{}` cannot be published.\n\
710-
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
711-
pkg.name(),
712-
);
713-
}
706+
let unpublishable = pkgs
707+
.iter()
708+
.filter(|pkg| pkg.publish() == &Some(Vec::new()))
709+
.map(|pkg| format!("`{}`", pkg.name()))
710+
.collect::<Vec<_>>();
711+
if !unpublishable.is_empty() {
712+
bail!(
713+
"{} cannot be published.\n\
714+
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.",
715+
unpublishable.join(", ")
716+
);
714717
}
715718

716719
let reg_name = match reg_or_index {

tests/testsuite/publish.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4105,7 +4105,7 @@ fn multiple_unpublishable_package() {
41054105
.masquerade_as_nightly_cargo(&["package-workspace"])
41064106
.with_status(101)
41074107
.with_stderr_data(str![[r#"
4108-
[ERROR] `dep` cannot be published.
4108+
[ERROR] `dep`, `main` cannot be published.
41094109
`package.publish` must be set to `true` or a non-empty list in Cargo.toml to publish.
41104110
41114111
"#]])

0 commit comments

Comments
 (0)