Skip to content

Fail to compile dependencies which in turn have renamed dependencies #14148

@usbalbin

Description

@usbalbin

Problem

I have two cargo projects, lets call them "the_bin" and "rename_deps".

"rename_deps" has a renamed dependency:

# rename_deps/Cargo.toml

[package]
name = "rename_deps"
version = "0.1.2"
edition = "2021"
publish = ["gitea"]

[dependencies]
embedded-hal-0-2 = { package = "embedded-hal", version = "0.2.7" }
// rename_deps/src/lib.rs
pub fn foo(_x: impl embedded_hal_0_2::PwmPin) { // <-- Using the renamed name here
    todo!()
}

This is then what gets published to my private registry

[package]
edition = "2021"
name = "rename_deps"
version = "0.1.2"
publish = ["gitea"]

[dependencies.embedded-hal-0-2]
version = "0.2.7"
package = "embedded-hal"

Compiling this works fine. I have then published this to my own private cargo registry(gitea). The publish check thing passes with no errors.

I then create a new binary project "the_bin", add "rename_deps" as dependency. And now cargo build fails to compile "rename_deps" when running cargo build on "the_bin". Same thing but with rename_deps { path = "some-path" } or git = and it compiles fine again.

   Compiling rename_deps v0.1.2 (registry `gitea`)
error[E0433]: failed to resolve: use of undeclared crate or module `embedded_hal_0_2`
 --> /home/albin/.cargo/registry/src/my-very-secret-gitea-registry/rename_deps-0.1.2/src/lib.rs:2:21
  |
2 | pub fn foo(_x: impl embedded_hal_0_2::PwmPin) {
  |                     ^^^^^^^^^^^^^^^^ use of undeclared crate or module `embedded_hal_0_2`
  |
help: there is a crate or module with a similar name
  |
2 | pub fn foo(_x: impl embedded_hal::PwmPin) {
  |                     ~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0433`.
error: could not compile `rename_deps` (lib) due to 1 previous error

Steps

  1. cargo new rename_deps --lib
  2. Add renamed dependency
  3. Use renamed dependency in rename_deps's code
  4. cargo publish
  5. cargo new the_bin
  6. cargo add rename_deps
  7. cargo build
  8. Boom - Fails to build rename_deps

Possible Solution(s)

Since what I receive from my registry seems correct this is likely not due to me using a private registry I think?

Notes

This is what gets published to my private registry (ignoring the comments)

[package]
edition = "2021"
name = "rename_deps"
version = "0.1.2"
publish = ["gitea"]

[dependencies.embedded-hal-0-2]
version = "0.2.7"
package = "embedded-hal"

Version

cargo 1.79.0 (ffa9cf99a 2024-06-03)
release: 1.79.0
commit-hash: ffa9cf99a594e59032757403d4c780b46dc2c43a
commit-date: 2024-06-03
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: Manjaro 24.0.2 (Wynsdey) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-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