Skip to content

Commit

Permalink
Auto merge of #6494 - ehuss:fix-unused-patch-warning, r=dwijnand
Browse files Browse the repository at this point in the history
Fix new unused patch warning.

The unused `[patch]` warning added in #6470 was misfiring if you build only a subset of a workspace that doesn't include the patch.

I'm about 80% confident this new logic is correct. It addresses the scenario I discovered, and I tested a bunch of commands (generate-lockfile, update, etc.) to make sure they all work. However, the many ways that `resolve_with_previous` is called is tricky to ensure every scenario works correctly.
  • Loading branch information
bors committed Dec 28, 2018
2 parents fef7802 + 7d11280 commit 9bf8592
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions tests/testsuite/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9bf8592

Please sign in to comment.