Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
These three commands form the daily Rust loop. cargo check type-checks without codegen — 5–10× faster than build, run it constantly while editing. cargo build produces actual binaries. cargo clippy runs an extra ~600 lints (pedantic, perf, correctness) on top of the type checker. The right rhythm: check on save, build before running, clippy before pushing. Don't skip clippy — it catches real bugs (stuff like if let Some(x) = y { } else { } that's actually a match).
cargo check, cargo build, and cargo test represent three distinct points on the compile-to-verify spectrum. cargo check runs type checking and borrow analysis without producing any binary — it's the fastest possible feedback loop during development. cargo build compiles to a real binary but skips test harness setup, while cargo test compiles a special test binary, runs your unit tests, and reports results. Using the right tool for the right moment cuts iteration time dramatically in large projects.
check should be ~5× faster than build.cargo check to run on save in your editor (VS Code: rust-analyzer does this; Neovim: rust-analyzer LSP). Now you get errors instantly.cargo clippy -- -W clippy::pedantic. This unlocks ~150 extra lints. Many will not apply, but reading them is educational.cargo clippy --all-targets -- -D warnings to CI. -D warnings turns warnings into hard fails — this is how you keep them from accumulating.Use these three in order. Each builds on the one before.
In one paragraph, explain the difference between `cargo check`, `cargo build`, and `cargo clippy`. When do I run each in a normal day?
What does `cargo check` skip that `cargo build` does — and why is that 5–10× faster? Cover MIR vs codegen vs linking.
Some clippy lints (like `clippy::pedantic` group) generate false positives. What's a sane way to manage that for a team — workspace-level `clippy.toml`, `#[allow(clippy::xxx)]` on individual items, opt-in groups?
# cargo check — type check only, no codegen:
$ time cargo check
Compiling myapp v0.1.0
Finished dev profile in 1.2s
# cargo build — full compile + link:
$ time cargo build
Finished dev profile in 8.4s
# cargo clippy — extra lints:
$ cargo clippy --all-targets --all-features -- -D warnings
warning: this loop could be written as a `for` loop
--> src/main.rs:5:5
|
5 | while i < v.len() {
| ^^^^^^^^^^^^^^^^^
|
= help: replace with: `for i in 0..v.len()`
= note: `#[warn(clippy::needless_range_loop)]` on by default
# typical CI line:
$ cargo clippy --all-targets --all-features --workspace -- -D warningscargo run