为什么 `cargo check` 之后 `cargo build` 会立即重新编译一些依赖项?

Why `cargo build` immediately after `cargo check` recompiles some dependencies?

cargo check 重新编译许多(但不是全部)依赖项后立即 cargo build 的可能原因是什么?

Cargo.toml

[package]
name = "greeter"
version = "0.1.0"
authors = ["Near Inc <hello@near.org>"]
edition = "2018"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
near-sdk = "3.1.0"

[profile.release]
codegen-units = 1
# Tell `rustc` to optimize for small code size.
opt-level = "z"
lto = true
debug = false
panic = "abort"
# Opt into extra safety checks on arithmetic operations 
overflow-checks = true

[workspace]
members = []

cargo check 不是构建。它只是检查您的代码是否可以编译,但不一定会构建任何东西。有关详细信息,请参阅 here

因此 cargo build 将需要实际建造一些箱子,这些箱子在 cargo check 期间没有建造。其他 crate 可能需要完全编译才能检查(例如 build.rs 脚本或程序宏中使用的 crate),因此当您 运行 cargo build.