Source replacements are ignored when producing compilation units #14821
Open
Description
opened on Nov 14, 2024
Problem
When replacing sources in .cargo/config.toml
so that two different sources point to the same vendored directory, cargo identifies a single package from two different sources as different, giving rise to a confusing error message where a type from a file is claimed to be distinct from itself:
error[E0308]: mismatched types
--> src/main.rs:2:10
|
2 | b::b(c::C {});
| ---- ^^^^^^^ expected `c::C`, found `C`
| |
| arguments to this function are incorrect
|
= note: `C` and `c::C` have similar names, but are actually distinct types
note: `C` is defined in crate `c`
--> /tmp/cargo-vendor-test/a/vendor/c/src/lib.rs:1:1
|
1 | pub struct C {}
| ^^^^^^^^^^^^
note: `c::C` is defined in crate `c`
--> /tmp/cargo-vendor-test/a/vendor/c/src/lib.rs:1:1
|
1 | pub struct C {}
| ^^^^^^^^^^^^
= note: perhaps two different versions of crate `c` are being used?
note: function defined here
--> /tmp/cargo-vendor-test/a/vendor/b/src/lib.rs:1:8
|
1 | pub fn b(_c: c::C) {}
| ^
Steps
- Clone https://github.com/P-E-Meunier/cargo-vendor-test
- Run a fake private registry from the root of the repo:
cd cargo-vendor-test
python -m http.server 8080 --bind 127.0.0.1 --directory .
- Run
cargo vendor ../vendor
from subdirectorya
, which yields a wrong output (as per Cargo vendor doesn't replace all sources used by dependencies in its output #14729). - The correct output, to be written to
a/.cargo/config.toml
, should be:
[source."sparse+http://localhost:8080/registry-y/"]
registry = "sparse+http://localhost:8080/registry-y/"
replace-with = "vendored-sources"
[source."sparse+http://localhost:8080/registry-x/"]
registry = "sparse+http://localhost:8080/registry-x/"
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
- Run
cargo build
from subdirectorya
.
Activity