如何诊断货物构建中的“找不到类型”错误?

问题描述 投票:0回答:1

我正在完成一个教程项目(此处为教程),该项目由一个包含两个二进制文件和一个库的 Rust 工作区组成,每个库都有自己的

Cargo.toml
。直接依赖关系并不算太多。这三个列表包含:

/store/Cargo.toml:

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

/服务器/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"

当我尝试使用

cargo check
进行构建时,当 Cargo 下载并编译直接和间接依赖项时,我收到几条消息,中间出现“找不到类型”错误。

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

我已确定错误不在于我的代码。因此我认为这是依赖项之一的问题,我也许应该更新版本。但我要问你的问题是:如何诊断此类错误?

通过错误中的这个 URL——“/Users/joe/.cargo/registry/src/github.com-1ecc6299db9ec823/core-foundation-0.9.3/src/mach_port.rs:17:16”——我推断问题依赖是

core-foundation
。但我不知道我的哪些依赖项依赖于那个板条箱。有没有办法使用 Cargo 来找出答案?

rust rust-cargo
1个回答
0
投票

运行

cargo tree -i [email protected]
。 (如果没有多个版本,版本号是可选的)。这将打印一个反向依赖树,显示包或工作区中
core-foundation
的每个依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.