Skip to content

Source replacements are ignored when producing compilation units #14821

Open
@P-E-Meunier

Description

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

  1. Clone https://github.com/P-E-Meunier/cargo-vendor-test
  2. 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 .
  1. Run cargo vendor ../vendor from subdirectory a, which yields a wrong output (as per Cargo vendor doesn't replace all sources used by dependencies in its output #14729).
  2. 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"
  1. Run cargo build from subdirectory a.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions