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.
Rust has the same culture as Go: opinionated tools, no debates. rustfmt formats to one canonical style. clippy lints across hundreds of rules. Configure both via rustfmt.toml and clippy.toml (sparingly), wire them into your editor on save and into CI as gating checks. A team that ships rustfmt+clippy from day 1 has clean diffs forever; a team that doesn't will rage-quit within months.
rustfmt and clippy are the two guardrails that keep Rust codebases consistent and idiomatic. rustfmt enforces a canonical style automatically — no debate, just run it. clippy is a static analysis linter that catches hundreds of common mistakes, performance anti-patterns, and non-idiomatic constructs that the compiler itself won't flag. Wiring both into your CI pipeline with --check flags means every pull request is verified to be formatted and lint-clean before it merges.
cargo fmt --all on the M1 hello project. If the diff is non-empty, you've found ungoverned formatting.cargo clippy -- -D warnings (the -D makes warnings hard errors). Fix every finding.rustfmt.toml setting max_width = 100 (or 80 — pick a side). Reformat. Note how cargo fmt is now project-aware.Use these three in order. Each builds on the one before.
In one paragraph, explain why the Rust ecosystem standardized on rustfmt+clippy and what cultural payoff that has (vs JS/Python where formatter wars are still alive).
How does clippy build on top of the rustc lints? Why are some lints in clippy and not in rustc itself?
On a real-world team, how do you handle clippy churn — new lints in new Rust versions making CI fail? Pin Rust version, allow specific lints, use `--cap-lints`?
# format every file in the workspace (in place):
$ cargo fmt --all
# show what would change without writing:
$ cargo fmt --all -- --check
# clippy with strict gating — typical CI line:
$ cargo clippy --all-targets --all-features --workspace -- -D warnings
# config files (commit these):
$ cat rustfmt.toml
edition = "2021"
max_width = 100
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
$ cat clippy.toml
msrv = "1.75"
# avoid over-config; a few project-specific allows go inline.
# pre-commit hook (.git/hooks/pre-commit):
#!/bin/sh
cargo fmt --all -- --check && cargo clippy --all-targets -- -D warningscargo run