Cargo: dependency resolution using []

This my be a little confusing but let me try my best to explain the situation using an example

I have a project called A. A is directly dependent on a package called B which is mentioned under A's [dependencies]
B is directly dependent on a package called C. B is also dependent on a package called D which is again directly dependent on C. The structure can be pictured as below.

A --> B
      B --> C
      B --> D
            D --> C

I want to add a fix to C and hence I fork it and push my changes.
I add the patch in A's Cargo.toml as

C = { git = "", rev = "abcdefg" }

The issues I'm seeing:

  1. This doesn't override C's source in B and D. Will adding the patch in top level Cargo.toml not work?
    is the only way to make this work is to also patch C in B and D?
  2. If the version of C is 0.1.0 in B and D, what version will my patch be considered as? <0.2.0 or >=0.2.0

It should work. From the docs I've linked below:

It’s also worth noting that [patch] applies transitively.

Maybe try deleting your Cargo.lock file.

The version in the Cargo.toml of your patch must be a version that is matched by the dependency specification of B and D. If both have set C = "0.1.0" for example, your patch must have a version 0.1.*, or else it won't be applied. So < 0.2.0

Documentation for overriding dependencies can be found here: Overriding Dependencies - The Cargo Book

Understanding the versioning helped me fix the issue.
Thanks @jofas :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.