diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 4447dc9699e..557a84039d8 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -60,10 +60,6 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> { } } - if !pkg.manifest().patch().is_empty() { - failure::bail!("published crates cannot contain [patch] sections"); - } - let (mut registry, reg_id) = registry( opts.config, opts.token.clone(), diff --git a/src/doc/man/cargo-publish.adoc b/src/doc/man/cargo-publish.adoc index ff9f782f47d..ae247f48641 100644 --- a/src/doc/man/cargo-publish.adoc +++ b/src/doc/man/cargo-publish.adoc @@ -19,7 +19,6 @@ registry. The default registry is https://crates.io. This performs the following steps: . Performs a few checks, including: - - No `[patch]` sections are allowed in the manifest. - Checks the `package.publish` key in the manifest for restrictions on which registries you are allowed to publish to. . Create a `.crate` file by following the steps in man:cargo-package[1]. diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 66c51b9d152..11e9d23ba49 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -930,17 +930,71 @@ fn publish_with_patch() { bar = { path = "bar" } "#, ) - .file("src/main.rs", "extern crate bar; fn main() {}") + .file( + "src/main.rs", + "extern crate bar; + fn main() { + bar::newfunc(); + }", + ) .file("bar/Cargo.toml", &basic_manifest("bar", "1.0.0")) - .file("bar/src/lib.rs", "") + .file("bar/src/lib.rs", "pub fn newfunc() {}") .build(); // Check that it works with the patched crate. p.cargo("build").run(); + // Check that verify fails with patched crate which has new functionality. p.cargo("publish --index") .arg(registry_url().to_string()) + .with_stderr_contains("[..]newfunc[..]") .with_status(101) - .with_stderr_contains("[ERROR] published crates cannot contain [patch] sections") .run(); + + // Remove the usage of new functionality and try again. + p.change_file("src/main.rs", "extern crate bar; pub fn main() {}"); + + p.cargo("publish --index") + .arg(registry_url().to_string()) + .run(); + + // Note, use of `registry` in the deps here is an artifact that this + // publishes to a fake, local registry that is pretending to be crates.io. + // Normal publishes would set it to null. + publish::validate_upload( + r#" + { + "authors": [], + "badges": {}, + "categories": [], + "deps": [ + { + "default_features": true, + "features": [], + "kind": "normal", + "name": "bar", + "optional": false, + "registry": "https://github.com/rust-lang/crates.io-index", + "target": null, + "version_req": "^1.0" + } + ], + "description": "foo", + "documentation": null, + "features": {}, + "homepage": null, + "keywords": [], + "license": "MIT", + "license_file": null, + "links": null, + "name": "foo", + "readme": null, + "readme_file": null, + "repository": null, + "vers": "0.0.1" + } + "#, + "foo-0.0.1.crate", + &["Cargo.toml", "Cargo.toml.orig", "src/main.rs"], + ); }