用途:面向 Rust 工具链的日常操作,覆盖 rustup(工具链安装与管理)、cargo(构建与包编排)、rustc(编译器)、clippy(lint)与 rustfmt(格式化)。工具边界:rustup 管理通道、组件、目标与版本固定;cargo 负责构建、依赖、测试、发布与 lint 配置;rustc 负责源码到二进制与代码生成标志;clippy 与 rustfmt 应始终通过 cargo clippy、cargo fmt 调用,而非独立二进制。
安装:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh,默认安装 stable 通道及 rustc、cargo、rustfmt、clippy。通道方面,stable 用于生产;beta 用于验证下一稳定版;nightly 仅在需要 #![feature(...)] 时使用,并应固定日期且记录原因。组件可用 rustup component add <name> 安装,如 rust-src、miri、llvm-tools、rustc-dev。
常用 cargo 子命令:cargo check(仅类型检查,反馈最快)、cargo build、cargo build --release、cargo run、cargo test、cargo clippy、cargo fmt、cargo doc --open、cargo update、cargo tree、cargo install、cargo publish、cargo bench、cargo fetch、cargo vendor。提交前可运行 cargo fmt && cargo clippy -- -D warnings && cargo test。
clippy 分类:correctness(DENY)、suspicious、style、complexity、perf 默认 warn;pedantic、restriction、nursery、cargo 默认 allow,需显式开启。clippy::all 覆盖前五类;restriction 不应整组启用,应逐条选择。lint 可在 Cargo.toml 的 [lints.clippy] 与 [lints.rust] 配置(Rust 1.74+),或用 crate 根属性与逐项 #[allow]。
实践:提交 rust-toolchain.toml 固定 channel、components、targets 与 profile,使 CI 与本地一致;交叉编译用 rustup target add 后加 --target;rustfmt.toml 应显式设置 edition;在 Cargo.toml 用 rust-version 声明 MSRV,1.84 起可用 MSRV 感知解析器。限制:nightly 特性不稳定,restriction lint 之间可能互相冲突,部分 rustfmt 选项仅 nightly 可用;资料未提供收费、价格与平台信息。