#17530·cargo

`cargo package --no-verify` with a replaced registry source fails to assume that dependencies will be published to the registry

Author: CAD97Created Sep 28, 2026Updated Sep 29, 2026
LabelsC-bugCommand-packageS-triage

Problem

Normally when running cargo package, "if we are packaging multiple inter-dependent crates, lock-files will be generated under the assumption that dependencies will be published to this registry.^1" This fails when source replacement is in use, making cargo package fail when it shouldn't.

Steps

  1. Create a workspace with two packages example-upstream and example-downstream, with example-downstream depending on example-upstream by both relative path and name/version. It is important that these packages do not exist on crates.io.
  2. Run cargo clean; cargo package --registry=crates-io --no-verify. It succeeds.
bash
$ cargo package --registry=crates-io --no-verify
   Packaging example-upstream v0.1.0 (/home/cad97/src/example/crates/example-upstream)
    Packaged 4 files, 1.3KiB (881B compressed)
   Packaging example-downstream v0.1.0 (/home/cad97/src/playground/crates/example-downstream)
    Updating crates.io index
    Packaged 4 files, 1.4KiB (889B compressed)
  1. Replace crates-io with a local registry source, e.g.
toml
[source.crates-io]
replace-with = "system"
[source.system]
directory = "/usr/share/cargo/registry"
  1. Run cargo clean; cargo package --registry=crates-io --no-verify. It fails.
bash
$ cargo package --registry=crates-io --no-verify --no-metadata
   Packaging example-upstream v0.1.0 (/home/cad97/src/example/crates/example-upstream)
    Packaged 4 files, 1.3KiB (881B compressed)
   Packaging example-downstream v0.1.0 (/home/cad97/src/example/crates/example-downstream)
error: failed to prepare local package for uploading

Caused by:
  no matching package named `example-upstream` found
  location searched: directory source `/usr/share/cargo/registry` (which is replacing registry `crates-io`)
  required by package `example-downstream v0.1.0 (/home/cad97/src/example/crates/example-downstream)`

Possible Solution(s)

Whatever is done to resolve as-if the other package has been published to the registry should overlay the dependency source instead of or in addition to overlaying the registry.

Notes

Disclaimer: this was discovered as part of my employment at Canonical. These are my own words, not Canonical's.

Version

cargo 1.98.1 (797e8a9bc 2026-08-05)
release: 1.98.1
commit-hash: 797e8a9bca276c1c9f9f738d2a20f484fa4eea9d
commit-date: 2026-08-05
host: x86_64-unknown-linux-gnu
libgit2: 1.9.4 (sys:0.21.0 vendored)
libcurl: 8.21.0-DEV (sys:0.4.90+curl-8.21.0 vendored ssl:OpenSSL/3.6.3)
ssl: OpenSSL 3.6.3 9 Jun 2026
os: Ubuntu 26.4.0 (resolute) [64-bit]