From 7d112803c5042f0201b0f45d7fb5e308701af0b6 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 27 Dec 2018 17:13:31 -0800 Subject: [PATCH] Fix new unused patch warning. --- src/cargo/ops/resolve.rs | 2 +- tests/testsuite/patch.rs | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/resolve.rs b/src/cargo/ops/resolve.rs index fe2ec3964..33f2a2c03 100644 --- a/src/cargo/ops/resolve.rs +++ b/src/cargo/ops/resolve.rs @@ -340,7 +340,7 @@ pub fn resolve_with_previous<'cfg>( warn, )?; resolved.register_used_patches(registry.patches()); - if warn { + if register_patches { // It would be good if this warning was more targeted and helpful // (such as showing close candidates that failed to match). However, // that's not terribly easy to do, so just show a general help diff --git a/tests/testsuite/patch.rs b/tests/testsuite/patch.rs index 11f5d7948..5ceca4c05 100644 --- a/tests/testsuite/patch.rs +++ b/tests/testsuite/patch.rs @@ -485,6 +485,50 @@ fn add_ignored_patch() { .run(); } +#[test] +fn no_warn_ws_patch() { + Package::new("c", "0.1.0").publish(); + + // Don't issue an unused patch warning when the patch isn't used when + // partially building a workspace. + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["a", "b", "c"] + + [patch.crates-io] + c = { path = "c" } + "#, + ) + .file("a/Cargo.toml", &basic_manifest("a", "0.1.0")) + .file("a/src/lib.rs", "") + .file( + "b/Cargo.toml", + r#" + [package] + name = "b" + version = "0.1.0" + [dependencies] + c = "0.1.0" + "#, + ) + .file("b/src/lib.rs", "") + .file("c/Cargo.toml", &basic_manifest("c", "0.1.0")) + .file("c/src/lib.rs", "") + .build(); + + p.cargo("build -p a") + .with_stderr( + "\ +[UPDATING] [..] +[COMPILING] a [..] +[FINISHED] [..]", + ) + .run(); +} + #[test] fn new_minor() { Package::new("bar", "0.1.0").publish();