cargo: patch was not used message does not adequately describe reason
Heya, not sure whether we consider usability issues bugs, but, it seemed the closest option.
When configuring [patch]es there are a variety of reasons the patch may not be used, resulting in a message like the following:
warning: Patch `SOMETHING` 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.
This gives a list of reasons that can be particularly difficult to debug, as well as the recommendation that cargo update may help, which is particularly helpful when this message is printed by cargo update. As an alternative, it would be great to print the specific reason the [patch] wasn’t used, and a proposed resolution, which I believe is in-line with other compiler error improvements.
Some possible examples:
warning: Patch `SOMETHING` was not used in the crate graph.
Patch version "0.14.0" from `../SOMETHING` does not meet package constraint ">0.15.0",
this may be resolved by updating the `SOMETHING` package version
warning: Patch `SOMETHING` was not used in the crate graph.
Patch version "0.14.0" does not match the package version in Cargo.lock,
this may be resolved by running `cargo update` to update the cargo lock file.
Related to: https://github.com/rust-lang/cargo/issues/8400
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 17 (9 by maintainers)
right, turns out to be a user error when you have a
gitdependency and try to patch with[patch.crates-io]… which is documented here. clearly a mistake on my part but, seems like it would be nice to provide a nudge in the right direction?with an
cargo new whateverproject and a clone ofhttps://github.com/rust-lang/login the same directory.the following works, as expected the
crates.ioversion is replaced with the local version:This does not work, which, perhaps should be obvious if you read
[patch.**crates-io**]but, this took me… some weeks 😕and this gives you the classic “not used in the crate graph” warning
the correct approach of course is to:
imo it’d be excellent to have something like:
I personally wouldn’t worry too much about more unusual situations like that. It would be nice to have the information about the original patch definition, but that may be quite difficult to do (since the unused patches are part of
Cargo.lock). If it is possible to provide an improvement for more common mistakes, I would focus on that (assuming that is on the easier side of implementation).@weihanglo There are many reasons why a patch could fail, so I would recommend trying to tackle individual examples instead of going for a general solution. I think the example above about using the wrong source (
[patch.crates-io]instead of the git location) shouldn’t be too hard to improve. I would iterate over the unused patches, and then queryresolvedif it contains anything close to the missing patch (such as looking for a package by name).Here is an example that does that. That example only works within a single source, so something similar will need to be done inside
resolve_with_previous(just look for a package by name, ignoring the source and version).