By the end of this lesson
Use Cargo checks without confusing style tools with correctness tests.
Before you start
- Rust 1.90.0 or later, a terminal and a plain-text editor. Examples were tested with Rust 1.90.0, Edition 2024 on Linux.
- Complete lesson 26, or be comfortable explaining and running its examples.
Three words to know
- Formatter
- A tool that rewrites source layout consistently.
- Lint
- A diagnostic suggesting a potential code issue.
- Dependency
- An external crate your package uses.
1. Understand the idea
cargo fmt applies rustfmt’s source layout; cargo clippy analyzes patterns and offers diagnostics. Neither replaces input validation or behavioural tests. Both are rustup components and may need installing if your chosen toolchain profile omitted them. A dependency can execute build scripts during compilation, so review its source and need rather than adding it for every small task.
2. Save, run and observe
Work in a fresh practice folder. Read each file label before copying: Rust source, Cargo configuration and terminal commands are different kinds of input.
cargo check --offline
cargo test --offlineWhat you should see · example output
The package is checked and its tests run. Exact progress output varies.
rustup component add rustfmt clippy
cargo fmt --check
cargo clippy --offline -- -D warningsWhat you should see · example output
Install components only when needed; fmt checks layout and Clippy reports diagnostics.
3. Explain the result
--offline prevents Cargo from reaching the network but cannot supply a missing dependency. Our final project uses only std and needs no registry crates. Cargo.lock records selected versions for reproducible dependency resolution; do not hand-edit versions without rerunning checks. A zero-warning result is not a claim that code is secure or exhaustive.
YOUR TURN
A small check before you continue
Does cargo check execute your unit tests?
Show a suggested answer
No. It checks compilation without running the tests. Use cargo test for execution.
Sources and scope
Documentation and examples reviewed 2026-10-18. Provider screens, package versions and output wording can differ. Examples show expected outcomes; they are not a claim that OpenViST connected to your server or verified your setup.
