Search code examples
rustrust-cargo

How can I diagnose this "cannot find type" error in a cargo build?


I'm working through a tutorial project (tutorial here) that consists of a Rust workspace with two binaries and one library, each with their own Cargo.toml. The direct dependencies are not too numerous. The three lists contain:

/store/Cargo.toml:

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"

/server/Cargo.toml:

[dependencies]
store = { path = "../store" }
serde = { version = "1", features = ["derive"] }
bincode = "1.3.1"
renet = "0.0.9"
log = "0.4"
env_logger="0.9.0"

/client/Cargo.toml:

[dependencies]
store = { path = "../store" }
anyhow = "1.0"
bevy = { version = "0.8", features = ["dynamic"] }
renet="0.0.9"
bevy_renet = "0.0.5"
bincode="1.3.1"

When I attempt a build, with cargo check, I'm getting several messages as Cargo downloads and compiles the direct and indirect dependencies, with a "cannot find type" error in the middle.

> cargo check
    Updating crates.io index
   Compiling proc-macro2 v1.0.66
   Compiling unicode-ident v1.0.11
   Compiling libc v0.2.147
    Checking cfg-if v1.0.0
   Compiling serde v1.0.175
   Compiling autocfg v1.1.0
   Compiling version_check v0.9.4
   Compiling syn v1.0.109
    Checking once_cell v1.18.0
   Compiling memchr v2.5.0
   Compiling ahash v0.7.6
    Checking byteorder v1.4.3
   Compiling thiserror v1.0.44
    Checking bitflags v1.3.2
   Compiling crossbeam-utils v0.8.16
   Compiling lock_api v0.4.10
    Checking pin-project-lite v0.2.10
   Compiling parking_lot_core v0.9.8
   Compiling quote v1.0.32
    Checking getrandom v0.2.10
    Checking log v0.4.19
   Compiling syn v2.0.27
    Checking scopeguard v1.2.0
   Compiling futures-core v0.3.28
    Checking tracing-core v0.1.31
    Checking fixedbitset v0.4.2
   Compiling slab v0.4.8
    Checking event-listener v2.5.3
    Checking concurrent-queue v2.2.0
    Checking tracing v0.1.37
    Checking fxhash v0.2.1
    Checking instant v0.1.12
    Checking fastrand v1.9.0
    Checking core-foundation-sys v0.8.5
    Checking waker-fn v1.1.0
    Checking parking v2.1.0
    Checking futures-io v0.3.28
   Compiling erased-serde v0.3.28
   Compiling uuid v1.4.1
    Checking futures-lite v1.13.0
    Checking async-lock v2.7.0
    Checking async-task v4.4.0
    Checking async-channel v1.9.0
    Checking num_cpus v1.16.0
   Compiling num-traits v0.2.16
    Checking thread_local v1.1.7
    Checking downcast-rs v1.2.0
    Checking bevy_ptr v0.8.1
    Checking core-foundation v0.9.3
   Compiling cc v1.0.79
    Checking foreign-types-shared v0.1.1
error[E0412]: cannot find type `CFIndex` in this scope
  --> /Users/joe/.cargo/registry/src/github.com-1ecc6299db9ec823/core-foundation-0.9.3/src/mach_port.rs:17:16
   |
17 |         order: CFIndex,
   |                ^^^^^^^ not found in this scope
   |
help: consider importing this type alias
   |
1  | use base::CFIndex;
   |

    Checking foreign-types v0.3.2
For more information about this error, try `rustc --explain E0412`.
error: could not compile `core-foundation` due to previous error
warning: build failed, waiting for other jobs to finish...
>

I have determined that the error is not with my code. Therefore I assume it's a problem with one of the dependencies, and I should perhaps update the version. But my question for you is this: How can I diagnose this type of error?

By this URL in the error -- "/Users/joe/.cargo/registry/src/github.com-1ecc6299db9ec823/core-foundation-0.9.3/src/mach_port.rs:17:16" -- I deduce that the problem dependency is core-foundation. But I don't know which of my dependencies depends on that crate. Is there a way to use Cargo to find that out?


Solution

  • Run cargo tree -i core-foundation@0.9.3. (The version number is optional if there are not multiple versions). This will print a tree of inverse dependencies, showing every dependent of core-foundation in your package or workspace.