Skip to content

Cargo downgrades transitive dependency that should not change #14446

Open
@konstin

Description

Problem

Our project, uv, depends on a git version of pubgrub. pubgrub depends on rustc-hash = ">=1.0.0, <3.0.0". uv has dependencies with both rustc-hash 1 and rustc-hash 2. At 6bd677d60d15ab950ae5466197cab4f3f2405bf4, Cargo.lock in uv has:

[[package]]
name = "pubgrub"
version = "0.2.1"
source = "git+https://github.com/astral-sh/pubgrub?rev=aaef464c1b0d8eea4ff9ffaee4f3458c236d10da#aaef464c1b0d8eea4ff9ffaee4f3458c236d10da"
dependencies = [
 "indexmap",
 "log",
 "priority-queue",
 "rustc-hash 2.0.0",
 "thiserror",
]

Each time i bump the pubgrub revision in Cargo.toml, cargo downgrades the rustc version, even though pubgrub's dependencies didn't change:

[[package]]
name = "pubgrub"
version = "0.2.1"
source = "git+https://github.com/astral-sh/pubgrub?rev=388685a8711092971930986644cfed152d1a1f6c#388685a8711092971930986644cfed152d1a1f6c"
dependencies = [
 "indexmap",
 "log",
 "priority-queue",
 "rustc-hash 1.1.0",
 "thiserror",
]

The only way to fix this is running cargo update -p rustc-hash@1.1.0 manually after each pubgrub update.

Steps

  • git clone https://github.com/astral-sh/uv && cd uv && git checkout 6bd677d60d15ab950ae5466197cab4f3f2405bf4
  • Update the git revision in Cargo.toml, e.g. to 388685a8711092971930986644cfed152d1a1f6c
  • Update the lockfile, e.g. cargo check
  • git diff:
diff --git a/Cargo.lock b/Cargo.lock
index d90529ebcf5e..15f283c3788c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2777,12 +2777,12 @@ dependencies = [
 [[package]]
 name = "pubgrub"
 version = "0.2.1"
-source = "git+https://github.com/astral-sh/pubgrub?rev=aaef464c1b0d8eea4ff9ffaee4f3458c236d10da#aaef464c1b0d8eea4ff9ffaee4f3458c236d10da"
+source = "git+https://github.com/astral-sh/pubgrub?rev=388685a8711092971930986644cfed152d1a1f6c#388685a8711092971930986644cfed152d1a1f6c"
 dependencies = [
  "indexmap",
  "log",
  "priority-queue",
- "rustc-hash 2.0.0",
+ "rustc-hash 1.1.0",
  "thiserror",
 ]
 
diff --git a/Cargo.toml b/Cargo.toml
index 94a65c8d0168..933484fe9740 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -112,7 +112,7 @@ pathdiff = { version = "0.2.1" }
 petgraph = { version = "0.6.4" }
 platform-info = { version = "2.0.2" }
 proc-macro2 = { version = "1.0.86" }
-pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "aaef464c1b0d8eea4ff9ffaee4f3458c236d10da" }
+pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "388685a8711092971930986644cfed152d1a1f6c" }
 pyo3 = { version = "0.21.0" }
 pyo3-log = { version = "0.10.0" }
 quote = { version = "1.0.36" }

Possible Solution(s)

During version resolution, cargo should use the version previously used for the package as preference, not another version in the lockfile, or if it has to use a version from the lockfile, it should use the higher version.

Notes

No response

Version

cargo 1.80.1 (376290515 2024-07-16)
release: 1.80.1
commit-hash: 37629051518c3df9ac2c1744589362a02ecafa99
commit-date: 2024-07-16
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 24.4.0 (noble) [64-bit]

Metadata

Assignees

No one assigned

    Labels

    A-dependency-resolutionArea: dependency resolution and the resolverA-gitArea: anything dealing with gitC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions