Skip to content

Using Rust Coding Standards in code review

Use this guide to review Rust against the rules a project has adopted.

For a focused walkthrough of AI-generated Rust quality and performance, read Anti AI Slop Rust; its review questions also apply to human-written code.

Start with the owning project

  1. Read the consumer repository's current issue, applicable architecture and safety rules, exact reviewed base and HEAD, and available test evidence.
  2. Confirm the project's adoption declaration, revision choice and scope. Record the RCS commit consulted. If the project has not adopted RCS, use the guidelines as suggestions.
  3. Apply the project's requirements first, including its architecture and safety rules. Resolve rule conflicts through its issue/decision process.

See adoption for the declaration format.

Select applicable rules

Read the standards index, then open only the rules relevant to the changed behavior and its surrounding call paths. Do not mechanically apply every rule to every PR.

Change touches Start with
Naming, module boundaries or public APIs Style and structure, Types and errors
File sizes, offsets, budgets, index conversions or serialization widths Numbers and bounds
Unsafe code, external input or user-owned data Safety and user-owned data
Decoding, archives, malformed data or input/resource limits Untrusted input
Filesystem identity, copying, publishing or uncertain retries Filesystem identity and completed effects
Native pathname representation, SQLite transactions or schema recovery Persistence and native paths
External tools, subprocess output or cancellation Processes and cancellation
Concurrent writer admission or shared mutable state Concurrency and tooling
Toolchain versions, format/lint or supported target checks Concurrency and tooling
File hashing, expensive helpers, database requests or repeated batches Performance and execution cost
Long-running work, terminal progress, verbose output or diagnostic logging Progress, diagnostics and logging
Behavior changes, error paths or public contracts Testing and documentation

Follow the execution path far enough to understand effects. The diff tells you where code changed, not necessarily where the problem occurs. Tests and Clippy can confirm important properties, but passing them does not establish that a file copy, durable transition or large-data call path is correct.

Prioritize verification by failure cost

Match review effort to what a wrong result would do, not whether a human or an AI agent typed the code. For low-risk, easily reversible work, normal tests and a clear diff may be sufficient. For a public API, compatibility check or other decision that callers rely on, inspect its promised behavior and test both rejection of invalid cases and acceptance of valid cases when relevant. For unsafe, FFI and consequential filesystem or durable-state transitions, trace the caller's proof obligations and failure boundaries carefully, even when coverage and automated tools are green.

Before delegating substantive work to an agent or another contributor, explain the load-bearing types, invariants, permitted assumptions, realistic failure cases, supported targets and what evidence would qualify the result. Afterward, review the design and assertions, not only test counts or formatting; do not waive close reading of high-risk native/unsafe code. Apply the risk-weighted verification workflow when it adds confidence. It complements RCS-TEST-004; it is not a universal request to run mutation tests, Miri or a sanitizer.

Classify a finding with evidence

An actionable review comment should state (and the PR/review should record the RCS commit actually consulted when applying RCS):

  • Rule: exact ID, such as RCS-NUM-001, plus the owning project's stricter rule if applicable.
  • Where: file and symbol, along with the call path or state transition that reaches it.
  • Trigger: reproducible input, race, error, or realistic workload; do not invent facts or timings.
  • Consequence: incorrect bytes, fabricated completion, rejected valid input, wasted I/O, or a specific maintenance hazard.
  • Smallest fix and test: what would establish the required behavior without weakening other invariants.
  • Verification: which checks were run on the exact reviewed revision and what has not been proven.

Severity follows the consumer's review policy. An evidence-backed correctness or data-safety failure generally needs a code change; a suggestion to rename a readable local helper normally does not. Advisory RCS rules are not automatic blockers. A Required rule also needs proof its applicability condition was met.

Example: a concrete review finding

RCS-NUM-001 — consequential overflow. plan.rs::checked_end computes start + bytes from an untrusted archive entry size. If the sum exceeds u64::MAX, behavior may panic or wrap depending on overflow settings, producing an invalid end offset. Return a range error from checked_add, and test both the largest valid span and an overflowing input.

The path and symbol above are illustrative, not a claim about any specific existing repository.

Example: not a defect by itself

"This file is long, and the code should use another trait."

Without a concrete comprehension problem, invariant risk, repeated work, or maintenance cost, this is an unsupported preference. Do not treat line counts, wrapper counts, or stylistic dissatisfaction as an acceptance criterion.

Trace performance without weakening safety

For expensive code, name the entry point and count work through called helpers. Separate independent checks required at distinct points in time from redundant work against a demonstrably stable object. If one verified large file is streamed multiple times, quantify the number of passes and expected byte volume; do not invent throughput or optimization results.

For example, rehashing one 4-GiB source nine times implies roughly 36 GiB of logical source reads, not proof that the operation takes any particular number of seconds. Before removing a pass, show which identity, concurrency and freshness guarantees survive.

See RCS-PERF-001 and the measurement guide for investigation methods.

Write the review result

Use the verdict language required by the owning project. Distinguish verified defects, supported recommendations, and unverified questions. Be explicit about which platform, code path and evidence were not checked.

Label self-review and independent review accurately: independent review requires a separate reviewer or process. If code changes after review, recheck the affected code and evidence at the new HEAD.

Checking rulebook changes

Run the documented validation commands from the repository root whenever rule IDs, headings or links change. The standard-library-only source checker validates the Markdown index and local links without a site builder. The Zensical build and --site check then confirm that generated headings, links and search output exist. The validator discovers rules from their headings and index; it never requires a hardcoded total.

Keep the rulebook maintainable

Link to applicable rules from review skills and read them during implementation and review. Propose changes to shared rules in this repository; handle project code and policy changes in that project's repository. See the adoption upgrade guidance for following main or updating a fixed revision.