Skip to content

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

Closed as duplicate of#11782
@J-ZhengLi

Description

@J-ZhengLi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.A-patchArea: [patch] table overrideC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions