Patching an indirect dependency with `package = "xxx"` renaming

Context

We have three crates:

  • parent
  • child
  • client

Where client depends on child and child depends on parent.

We want to patch (overriding) the parent used by child.

First Try: with package renaming

Here, we would use the patch syntax in client/Cargo.toml:

[patch.'https://github.com/billy1624/test-cargo-patch.git'] 
parent = { path = "../parent-x", package = "parent-x" } 

Overriding parent with parent-x. The parent-x is being renamed as parent as follows:

Checkout the branch.

$ cd client

$ cargo b
   Compiling child v0.1.0 (https://github.com/billy1624/test-cargo-patch.git#12ec7298)
error[E0061]: this function takes 1 argument but 0 arguments were supplied
 --> /Users/billy/.cargo/git/checkouts/test-cargo-patch-ae21da568fb3f50c/12ec729/child/src/lib.rs:2:5
  |
2 |     parent::func();
  |     ^^^^^^^^^^^^-- an argument of type `String` is missing
  |
note: function defined here
 --> /Users/billy/.cargo/git/checkouts/test-cargo-patch-ae21da568fb3f50c/12ec729/parent/src/lib.rs:1:8
  |
1 | pub fn func(_: String) -> &'static str {
  |        ^^^^
help: provide the argument
  |
2 |     parent::func(/* String */);
  |                 ~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0061`.
error: could not compile `child` (lib) due to 1 previous error

$ cargo tree
client v0.1.0 (/Users/billy/Projects/test-cargo-patch/client)
├── child v0.1.0 (https://github.com/billy1624/test-cargo-patch.git#12ec7298)
│   └── parent v0.1.0 (https://github.com/billy1624/test-cargo-patch.git#12ec7298)
└── parent-x v0.1.0 (/Users/billy/Projects/test-cargo-patch/parent-x)

From the result of cargo build and cargo tree, we saw that it did NOT patch (override) the parent dependency that's used in child.

Second Try: without package renaming

Overriding parent with parent-x. The package in parent-x is being named as parent, without any renaming:

Checkout the branch.

$ cd client

❯ cargo b
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s

❯ cargo tree
client v0.1.0 (/Users/billy/Projects/test-cargo-patch/client)
├── child v0.1.0 (https://github.com/billy1624/test-cargo-patch.git#12ec7298)
│   └── parent v0.1.0 (/Users/billy/Projects/test-cargo-patch/parent-x)
└── parent v0.1.0 (/Users/billy/Projects/test-cargo-patch/parent-x)

Here, we successfully patch (override) the parent dependency that's used in child.

Questions

  • Is this the intended behaviour?

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.