Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
alcolmenar opened this issue Aug 9, 2023 · 2 comments
Open
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-patch Area: [patch] table override C-bug Category: bug S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.

Comments

@alcolmenar
Copy link
Contributor

Problem

A known unused patch isn't marked unused and doesn't emit a warning when there is another used patch using the same dependency.

e.g.

[patch.crates-io]
bar = { git = "test" }

[patch."foo"]
bar = { git = "test" }

if the crates-io patch is used and the foo patch is unused, foo will not be marked as unused.

Steps

# Cargo.toml

[workspace]
members = [ "my-member" ]

[patch.'https://github.com/foo/bar.git']
serde = { git = "https://github.com/serde-rs/serde.git" }

[patch.crates-io]
serde = { git = "https://github.com/serde-rs/serde.git" }
# my-member/Cargo.toml
[package]
name = "my-member"
version = "0.1.0"

[dependencies]
serde = "1"

Execute cargo update

Expectation

A warning of the foo/bar patch being unused is emitted and a section in the Cargo.lock file for it.

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.73.0-nightly (45782b6b8 2023-07-05)
release: 1.73.0-nightly
commit-hash: 45782b6b8afd1da042d45c2daeec9c0744f72cc7
commit-date: 2023-07-05
host: aarch64-apple-darwin
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 7.79.1 (sys:0.4.63+curl-8.1.2 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Mac OS 12.5.1 [64-bit]
@alcolmenar alcolmenar added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Aug 9, 2023
@weihanglo
Copy link
Member

Maybe I was wrong but this looks like the same as #12464, no?

@alcolmenar
Copy link
Contributor Author

Maybe I was wrong but this looks like the same as #12464, no?

I think they are slightly different. Although, the probability of this issue's use case is probably pretty low? I'm not sure if we even support patching a dependency with different sources with the same dependency.

The crux of this issue is one of the patch's dependency is applied to the graph so the other unused patch is marked as used because both patches' dependencies are the same. The current logic to mark patches as used isn't taking into account the original patched dependency's source.

@weihanglo weihanglo added A-diagnostics Area: Error and warning messages generated by Cargo itself. S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. A-patch Area: [patch] table override and removed S-triage Status: This issue is waiting on initial triage. labels Jun 3, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-patch Area: [patch] table override C-bug Category: bug S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.
Projects
None yet
Development

No branches or pull requests

2 participants