diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 3606e708d89..80772e03998 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -134,10 +134,16 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> { let reg_name = publish_registry .clone() .unwrap_or_else(|| CRATES_IO_REGISTRY.to_string()); - if !allowed_registries.contains(®_name) { + if allowed_registries.is_empty() { bail!( "`{}` cannot be published.\n\ - The registry `{}` is not listed in the `publish` value in Cargo.toml.", + `package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing.", + pkg.name(), + ); + } else if !allowed_registries.contains(®_name) { + bail!( + "`{}` cannot be published.\n\ + The registry `{}` is not listed in the `package.publish` value in Cargo.toml.", pkg.name(), reg_name ); diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index d0851f62407..f121426ae07 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -325,7 +325,7 @@ fn unpublishable_crate() { .with_stderr( "\ [ERROR] `foo` cannot be published. -The registry `crates-io` is not listed in the `publish` value in Cargo.toml. +`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing. ", ) .run(); @@ -655,7 +655,7 @@ fn registry_not_in_publish_list() { .with_stderr( "\ [ERROR] `foo` cannot be published. -The registry `alternative` is not listed in the `publish` value in Cargo.toml. +The registry `alternative` is not listed in the `package.publish` value in Cargo.toml. ", ) .run(); @@ -684,7 +684,7 @@ fn publish_empty_list() { .with_stderr( "\ [ERROR] `foo` cannot be published. -The registry `alternative` is not listed in the `publish` value in Cargo.toml. +`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing. ", ) .run(); @@ -819,7 +819,7 @@ fn publish_fail_with_no_registry_specified() { .with_stderr( "\ [ERROR] `foo` cannot be published. -The registry `crates-io` is not listed in the `publish` value in Cargo.toml. +The registry `crates-io` is not listed in the `package.publish` value in Cargo.toml. ", ) .run(); @@ -848,7 +848,7 @@ fn block_publish_no_registry() { .with_stderr( "\ [ERROR] `foo` cannot be published. -The registry `alternative` is not listed in the `publish` value in Cargo.toml. +`package.publish` is set to `false` or an empty list in Cargo.toml and prevents publishing. ", ) .run(); @@ -880,7 +880,7 @@ fn publish_with_crates_io_explicit() { .with_stderr( "\ [ERROR] `foo` cannot be published. -The registry `alternative` is not listed in the `publish` value in Cargo.toml. +The registry `alternative` is not listed in the `package.publish` value in Cargo.toml. ", ) .run();