Skip to content

[feat] provide some way to suppress unused patch warnings #15527

New issue

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

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

Already on GitHub? Sign in to your account

Closed
J-ZhengLi opened this issue May 15, 2025 · 1 comment
Closed

[feat] provide some way to suppress unused patch warnings #15527

J-ZhengLi opened this issue May 15, 2025 · 1 comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-patch Area: [patch] table override C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@J-ZhengLi
Copy link
Member

Problem

The [patch] section in .cargo/config.toml is very useful to override certain dependencies (even if it's no uploaded to crates.io) of multiple projects.
But the downside is, for projects that do not use those patched dependencies, cargo will repeatedly show warnings about those being unused, which seems annoying over time.

Example

In .cargo/config.toml

[patch.crates-io]
foo = { path = "/path/to/foo" }
bar = { path = "/path/to/bar" }

after running

cargo init hello_world
cargo run
warning: Patch `foo v0.1.0 (/path/to/foo)` was not used in the crate graph.
Patch `bar v0.1.0 (/path/to/bar)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.

Proposed Solution

possible solutions (might not be the best)

  1. Add a configuration key under [patch]:
    [patch.crates-io]
    ...
    allow-unused = true
  2. Skip unused patch warning entirely if the [patch] configuration is coming from config.toml

Notes

No response

@J-ZhengLi J-ZhengLi added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels May 15, 2025
@weihanglo weihanglo added A-diagnostics Area: Error and warning messages generated by Cargo itself. A-patch Area: [patch] table override S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-triage Status: This issue is waiting on initial triage. labels May 15, 2025
@weihanglo
Copy link
Member

The problem of patch-in-confifg affects more than warnings, see

As as #15130 has called out, this feature was expected to have these defects. We might need to reconsider it as a whole.

Speaking of suppressing warnings, this is seemingly a duplicate of #11782, which is tracked in #12235, so close in favor of those. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Error and warning messages generated by Cargo itself. A-patch Area: [patch] table override C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

2 participants