Replacing dependencies with patch

Minimum Rust version: 1.21

The [patch] section of your Cargo.toml can be used when you want tooverride certain parts of your dependency graph.

Cargo has a [replace] feature that is similar; while we don't intend to deprecateor remove [replace], you should prefer [patch] in all circumstances.

So what’s it look like? Let’s say we have a Cargo.toml that looks like this:

  1. [dependencies]
  2. foo = "1.2.3"

In addition, our foo package depends on a bar crate, and we find a bug in bar.To test this out, we’d download the source code for bar, and then update ourCargo.toml:

  1. [dependencies]
  2. foo = "1.2.3"
  3. [patch.crates-io]
  4. bar = { path = '/path/to/bar' }

Now, when you cargo build, it will use the local version of bar, ratherthan the one from crates.io that foo depends on. You can then try out yourchanges, and fix that bug!

For more details, see the documentation forpatch.