Rust duplicate dependencies

  Kiến thức lập trình

I’m trying to use a toy code example my Cargo.toml is:

[package]
name = "reth_mempool"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reth-transaction-pool = { git = "https://github.com/paradigmxyz/reth.git", tag = "v0.2.0-beta.5"}

I get many errors compiling reth-primitives. The first one is:

error[E0308]: mismatched types
   --> /home/ittay/.cargo/git/checkouts/reth-36d3ea1d1152b20c/54f75cd/crates/primitives/src/chain/spec.rs:28:28
    |
28  |           genesis_hash: Some(b256!(
    |  _______________________----_^
    | |                       |
    | |                       arguments to this enum variant are incorrect
29  | |             "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
30  | |         )),
    | |_________^ expected `alloy_primitives::FixedBytes<32>`, found `revm_primitives::FixedBytes<32>`
    |
    = note: `revm_primitives::FixedBytes<32>` and `alloy_primitives::FixedBytes<32>` have similar names, but are actually distinct types
note: `revm_primitives::FixedBytes<32>` is defined in crate `alloy_primitives`
   --> /home/ittay/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-primitives-0.7.0/src/bits/fixed.rs:33:1
    |
33  | pub struct FixedBytes<const N: usize>(#[into_iterator(owned, ref, ref_mut)] pub [u8; N]);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `alloy_primitives::FixedBytes<32>` is defined in crate `alloy_primitives`
   --> /home/ittay/.cargo/registry/src/index.crates.io-6f17d22bba15001f/alloy-primitives-0.6.4/src/bits/fixed.rs:33:1
    |
33  | pub struct FixedBytes<const N: usize>(#[into_iterator(owned, ref, ref_mut)] pub [u8; N]);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: perhaps two different versions of crate `alloy_primitives` are being used?
help: the type constructed contains `revm_primitives::FixedBytes<32>` due to the type of the argument passed
   --> /home/ittay/.cargo/git/checkouts/reth-36d3ea1d1152b20c/54f75cd/crates/primitives/src/chain/spec.rs:28:23
    |
28  |            genesis_hash: Some(b256!(
    |  ________________________^____-
    | | _______________________|
    | ||
29  | ||             "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"
30  | ||         )),
    | ||_________-^
    | |__________|
    |            this argument influences the type of `Some`
note: tuple variant defined here
   --> /home/ittay/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:578:5
    |
578 |     Some(#[stable(feature = "rust1", since = "1.0.0")] T),
    |     ^^^^

Indeed, alloy-primitives appears in both 0.6.4 and 0.7.0.

If I checkout the reth repository (using the same tag) and build, it works and cargo tree shows it only uses 0.7.0.

I don’t know why 0.6.4 is used or how to resolve it. In particular, I’d be happy for an explanation about why cargo even allows the same library to be used in multiple versions (according to cargo tree, sometimes for the same crate).

LEAVE A COMMENT