Build Your Own Guardrails
Youâre going to spend two days reviewing code you didnât write. The reviewing is manual. Enforcing what you find doesnât have to be. Rustâs tooling can turn a review finding into a check that runs on every build. And the agent that wrote the code is good at writing that configuration too.
The pattern:
- A review catches a problem: an
unwrap()on input, a dependency nobody vetted, a test that asserts nothing. - You fix the instance.
- You ask the agent to add a check that rejects the whole class from now on.
A prompt for step 3 looks like this:
Add a Clippy configuration that rejects this class of code. Show me the lint names, set the levels in the crate root, and add a
clippy.tomlwithdisallowed-methodsfor the calls we banned in review.
The agent knows the lint tables better than most of us do. You decide what must never happen. The tooling checks it on every change after that, including the agentâs own.
Tools weâll use or mention
- Clippy with a project configuration. Running default Clippy is a
start. A per-project policy does more: lint levels in the crate root
(
#![warn(clippy::unwrap_used)]and similar), aclippy.tomlwithdisallowed-methodsanddisallowed-typesfor calls your review banned, and--deny warningsin CI. Project A sets one up for the parser this afternoon. - Miri interprets your code and detects undefined behavior and
memory errors that tests can miss. Run it whenever
unsafeappears. Itâs also cheap to run when none does.cargo +nightly miri teston Project B takes about two minutes. - mutest-rs mutates your code and reruns your tests. A mutant that survives marks a spot where the suite asserts nothing. This is how you check whether the agentâs green tests verify anything. Project Câs metrics tests are a good target.
- Loom checks concurrent code by exploring thread interleavings. Nothing in this course is concurrent, so we only mention it: know that it exists, and reach for it when threads arrive.
- Kani proves properties by bounded model checking. A passing test says âwe found no failing inputâ. A Kani proof says âno input up to this size can failâ. Writing one proof for the Project C arbiter is a stretch goal.
- Verus extends Rust with machine-checked specifications. Weâll not use it in this course. Itâs worth knowing about for contracts that matter enough to verify fully.
Why this works in Rust
Every tool on that list leans on the same property: in Rust the contracts live in the types, and the toolchain can be programmed against them. A lint you configure today enforces a review decision on every line written after it, including the ones the agent writes next week. So when you ask the agent for code, ask for the guardrail in the same prompt.