Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The dependency resolution is confused when using git dependency and there's a lockfile #11490

Closed
StyMaar opened this issue Dec 16, 2022 · 3 comments
Labels
A-git Area: anything dealing with git A-lockfile Area: Cargo.lock issues C-bug Category: bug S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@StyMaar
Copy link

StyMaar commented Dec 16, 2022

Problem

I'm working on some piece of proprietary code, and for the internal dependencies, we use git repositories instead of crates on crates.io or some internal registry.

Today I faced I really annoying error message:

error[E0308]: mismatched types
 --> src/main.rs:6:9
  |
6 |     foo(x);
  |     --- ^ expected enum `lower::X`, found enum `upper::X`
  |     |
  |     arguments to this function are incorrect
  |
  = note: enum `upper::X` and enum `lower::X` have similar names, but are actually distinct types
note: enum `upper::X` is defined in crate `lower`
 --> /home/stymaar/.cargo/git/checkouts/repro_cargo_lower-dc970fbba3cb3609/5914bef/src/lib.rs:1:1
  |
1 | pub enum X{
  | ^^^^^^^^^^
note: enum `lower::X` is defined in crate `lower`
 --> /home/stymaar/.cargo/git/checkouts/repro_cargo_lower-dc970fbba3cb3609/5914bef/src/lib.rs:1:1
  |
1 | pub enum X{
  | ^^^^^^^^^^
  = note: perhaps two different versions of crate `lower` are being used?
note: function defined here
 --> /home/stymaar/.cargo/git/checkouts/repro_cargo_lower-dc970fbba3cb3609/5914bef/src/lib.rs:6:8
  |
6 | pub fn foo(x:X){
  |        ^^^

So it complains that the type comes from different versions of the lower crate, whereas it comes from the same version as we can see in the error message itself (for both, it's repro_cargo_lower-dc970fbba3cb3609/5914bef).

I was very confused for a while and then I managed to understand what's going on an reproduce it:

Steps

  1. git clone git@github.com:StyMaar/repro_cargo_top.git
  2. cargo check

Notes

The problem comes from the upper dependency which does not specify the target commit (there is no rev in the declaration of the lower dependency in upper) but there's a Cargo.lock file which points to the same revision of lower as the one being used in the top-level crate.

In the end, the lower dependency is imported twice for the same revision, since cargo doesn't realize that it's in fact the same revision, and then rustc complains about the presence of two different types.

Version

cargo 1.67.0-nightly (eb5d35917 2022-11-17)
release: 1.67.0-nightly
commit-hash: eb5d35917b2395194593c9ca70c3778f60c1573b
commit-date: 2022-11-17
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:OpenSSL/1.1.1q)
os: Linux 19.3 (tricia) [64-bit]
@StyMaar StyMaar added the C-bug Category: bug label Dec 16, 2022
@StyMaar
Copy link
Author

StyMaar commented Dec 16, 2022

BTW, here's the Cargo.lock file, in here the problem is pretty obvious.

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "lower"
version = "0.1.0"
source = "git+ssh://git@github.com/StyMaar/repro_cargo_lower?rev=5914bef#5914befb63196597c42d3fe1775e736b0d6bcf6e"

[[package]]
name = "lower"
version = "0.1.0"
source = "git+ssh://git@github.com/StyMaar/repro_cargo_lower#5914befb63196597c42d3fe1775e736b0d6bcf6e"

[[package]]
name = "top"
version = "0.1.0"
dependencies = [
 "lower 0.1.0 (git+ssh://git@github.com/StyMaar/repro_cargo_lower?rev=5914bef)",
 "upper",
]

[[package]]
name = "upper"
version = "0.1.0"
source = "git+ssh://git@github.com/StyMaar/repro_cargo_upper?rev=a810b8e#a810b8ebf8f759635bc5d14dd16ed9ea556452c2"
dependencies = [
 "lower 0.1.0 (git+ssh://git@github.com/StyMaar/repro_cargo_lower)",
]

@weihanglo
Copy link
Member

Thank you for the report. This is indeed unlucky :(

There are some issues in a similar situation, such as #8293. #10256 (comment) also mentioned that Cargo cannot figure out two GitSources with different branch are actually the same revision. Haven't looked thoroughly into source code but I guess part of the cause could be how Cargo distinguishes different SourceKind. The Cargo.lock serialization problem you mentioned need to address as well.

@epage
Copy link
Contributor

epage commented Nov 3, 2023

This looks to be a duplicate of #7497, closing in favor of that. If there is a reason we should reconsider this, let us know!

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git A-lockfile Area: Cargo.lock issues C-bug Category: bug S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

3 participants