cargo: "can't find crate for..." proc-macro crates when the crate is clearly present and is passed to rustc

Problem

When compiling some crates (poem 3.1.10, salvo 0.78.0), I expect them to build; they fail to build with errors like:

error[E0463]: can't find crate for `salvo_macros`
  --> /home/nora/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/salvo_core-0.78.0/src/lib.rs:31:9
   |
31 | pub use salvo_macros::handler;
   |         ^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `salvo_macros`
  --> /home/nora/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/salvo_core-0.78.0/src/lib.rs:33:9
   |
33 | pub use salvo_macros as macros;
   |         ^^^^^^^^^^^^ can't find crate

error[E0463]: can't find crate for `salvo_macros`
  --> /home/nora/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/salvo_core-0.78.0/src/lib.rs:85:13
   |
85 |     pub use salvo_macros::{Extractible, handler};
   |             ^^^^^^^^^^^^ can't find crate

For more information about this error, try `rustc --explain E0463`.
error: could not compile `salvo_core` (lib) due to 3 previous errors

Steps

  1. cargo new whatever && cd whatever
  2. cargo add poem (or salvo)
  3. cargo build

However, I tried this on a new VM and wasn’t able to reproduce it. It’s something to do with my system, and I haven’t yet figured out what.

Possible Solution(s)

I tried uninstalling (rustup self uninstall) and reinstalling Rust, as well as cargo clean and rm -r ~/.cargo/registry/cache.

This appears not to happen under rust 1.80 but does happen under 1.81.

Notes

I ran cargo build --verbose and can see that the “missing” crates are indeed being passed to rustc:

/home/nora/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc 
--crate-name salvo_core 
--edition=2024 /home/nora/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/salvo_core-0.78.0/src/lib.rs 
# ...
--extern salvo_macros=/tmp/salvotest/target/debug/deps/libsalvo_macros-2d16cc326ba6665d.so 
# ...
--cap-lints allow`

Version

cargo 1.86.0 (adf9b6ad1 2025-02-28)
release: 1.86.0
commit-hash: adf9b6ad14cfa10ff680d5806741a144f7163698
commit-date: 2025-02-28
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.0-DEV (sys:0.4.79+curl-8.12.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Debian 12.0.0 (bookworm) [64-bit]

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (12 by maintainers)

Most upvoted comments

@midnightveil That’s normal. rustc does not implicitly have a search path for transitive dependencies. You’ll need to add -L build for it to find them.

Do you have the Nix package manager installed? I am using Nix on Ubuntu and ran into a similar issue with wasmtime. Removing gcc that was installed via the Nix Home Manager solved it for me. Someone else on the Rust user forums seems to have encountered the same problem.