Skip to content

fix(resolve): detect unused patches when multiple patches share a PackageId#16987

Open
raushan728 wants to merge 2 commits into
rust-lang:masterfrom
raushan728:Fix-12471
Open

fix(resolve): detect unused patches when multiple patches share a PackageId#16987
raushan728 wants to merge 2 commits into
rust-lang:masterfrom
raushan728:Fix-12471

Conversation

@raushan728
Copy link
Copy Markdown
Contributor

Fixes #12471

Previously, Cargo determined patch usage solely by checking if the PackageId existed in the crate graph, which caused false positives if multiple patch sources pointed to the same dependency.

Updated register_used_patches and emit_warnings_of_unused_patches to independently verify patch usage by inspecting graph edges for specific (CanonicalUrl, PackageId) pairs.

Left Resolve::unused_patches as Vec<PackageId> to ensure strict Cargo.lock backward compatibility without altering the serialized format.

@rustbot rustbot added A-dependency-resolution Area: dependency resolution and the resolver S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 11, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 11, 2026

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

Comment thread src/cargo/core/resolver/resolve.rs Outdated
Comment thread src/cargo/core/resolver/resolve.rs Outdated
…kageId

Previously, Cargo tracked used patches solely by PackageId. If multiple sources patched the same dependency, unused patches were incorrectly marked as used.

This updates the logic to track usage by both source URL and PackageId in-memory, ensuring accurate warnings while keeping Cargo.lock backward-compatible.

Fixes rust-lang#12471
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-dependency-resolution Area: dependency resolution and the resolver S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unused patch with same dependency as a used patch isn't marked unused

4 participants