Rust Code Review
Includes all guidelines from code-review skill, plus Rust-specific rules.
No unwrap in Non-test Code
The reviewer MUST:
- Flag every
unwrap(), unwrap_err(), or expect_err() outside tests.
Preferred alternatives:
- Use
? and propagate errors when the function returns Result.
- Handle errors explicitly (map to a domain error, log and fallback, or early return).
- Use
expect() only when failure is logically impossible or globally fatal, and the message explains why.
Bad:
let cfg = read_config().unwrap();
Better:
let cfg = read_config()?;
Acceptable only with proof:
let cfg = read_config().expect(
"config is validated and loaded at startup; reaching here means startup checks passed"
);
The reviewer MUST reject vague expect messages (e.g. "should not fail").
No panic! in Non-test Code
The reviewer MUST:
- Flag all
panic!, todo!, and unimplemented! outside tests.
The reviewer SHOULD:
- Prefer returning and propagating proper errors.
- Fail early at startup via error returns instead of panics deep in logic.
- Encourage tests to use panics and unwraps only with clear messages (e.g.
expect("reason")).
unreachable!() Usage
The reviewer MUST:
- Flag
unreachable!() unless a clear invariant explanation is provided.
It MAY be accepted if:
- The branch is genuinely impossible by construction.
- A comment documents the invariant (why this branch cannot be reached).
Otherwise, prefer returning a domain error instead of unreachable!().
No Silently Ignored Errors (Non-test Code)
The reviewer MUST:
- Flag any ignored
Result or Option unless the error is handled or logged, there is a clear comment explaining why ignoring is safe, or the error type is () and this is intentional.
Bad:
let _ = do_something_fallible();
do_something_fallible().ok();
Acceptable:
if let Err(e) = do_something_fallible() {
log::warn!("failed to do something: {}", e);
}
// Safe to ignore: telemetry failures do not affect correctness.
let _ = send_telemetry(&metrics);
Tests MAY ignore errors, but explicit assertions are encouraged.
Idiomatic Rust and Built-ins
The reviewer SHOULD:
- Suggest
? for simple error propagation instead of manual match.
- Use iterator methods (
map, filter, collect, etc.) when they simplify logic.
- Use
Option and Result combinators (map, and_then, ok_or, etc.) where they make code clearer.
The reviewer MUST NOT:
- Suggest overly clever refactors that hurt readability.
Performance
The reviewer SHOULD:
- Point out obvious waste such as repeated
to_string or clone in hot loops, or missing with_capacity for growing collections.
The reviewer MUST:
- Favor correctness and clarity over small micro-optimizations.
- Avoid speculative performance claims without a clear reason.
Documentation and Comments
The reviewer SHOULD:
- Ensure new or changed public APIs have basic
/// docs covering behavior, arguments, return values, and possible errors.
- Encourage comments where logic is non-obvious, especially around
unsafe code, concurrency and ordering assumptions, or invariants the type system does not enforce.
The reviewer SHOULD NOT:
- Request redundant "code-as-English" comments.
1---2name: code-review-rust3description: Rust-specific code review guidelines focusing on error handling, safety, and idiomatic patterns4---5
6# Rust Code Review
7
8Includes all guidelines from code-review skill, plus Rust-specific rules.
9
10## No `unwrap` in Non-test Code
11
12The reviewer MUST:
13- Flag every `unwrap()`, `unwrap_err()`, or `expect_err()` outside tests.
14
15Preferred alternatives:
16- Use `?` and propagate errors when the function returns `Result`.
17- Handle errors explicitly (map to a domain error, log and fallback, or early return).
18- Use `expect()` only when failure is logically impossible or globally fatal, and the message explains why.
19
20Bad:
21```rust
22let cfg = read_config().unwrap();
23```
24
25Better:
26```rust
27let cfg = read_config()?;
28```
29
30Acceptable only with proof:
31```rust
32let cfg = read_config().expect(
33 "config is validated and loaded at startup; reaching here means startup checks passed"
34);
35```
36
37The reviewer MUST reject vague `expect` messages (e.g. "should not fail").
38
39## No `panic!` in Non-test Code
40
41The reviewer MUST:
42- Flag all `panic!`, `todo!`, and `unimplemented!` outside tests.
43
44The reviewer SHOULD:
45- Prefer returning and propagating proper errors.
46- Fail early at startup via error returns instead of panics deep in logic.
47- Encourage tests to use panics and unwraps only with clear messages (e.g. `expect("reason")`).
48
49## `unreachable!()` Usage
50
51The reviewer MUST:
52- Flag `unreachable!()` unless a clear invariant explanation is provided.
53
54It MAY be accepted if:
55- The branch is genuinely impossible by construction.
56- A comment documents the invariant (why this branch cannot be reached).
57
58Otherwise, prefer returning a domain error instead of `unreachable!()`.
59
60## No Silently Ignored Errors (Non-test Code)
61
62The reviewer MUST:
63- Flag any ignored `Result` or `Option` unless the error is handled or logged, there is a clear comment explaining why ignoring is safe, or the error type is `()` and this is intentional.
64
65Bad:
66```rust
67let _ = do_something_fallible();
68do_something_fallible().ok();
69```
70
71Acceptable:
72```rust
73if let Err(e) = do_something_fallible() {
74 log::warn!("failed to do something: {}", e);
75}
76
77// Safe to ignore: telemetry failures do not affect correctness.
78let _ = send_telemetry(&metrics);
79```
80
81Tests MAY ignore errors, but explicit assertions are encouraged.
82
83## Idiomatic Rust and Built-ins
84
85The reviewer SHOULD:
86- Suggest `?` for simple error propagation instead of manual `match`.
87- Use iterator methods (`map`, `filter`, `collect`, etc.) when they simplify logic.
88- Use `Option` and `Result` combinators (`map`, `and_then`, `ok_or`, etc.) where they make code clearer.
89
90The reviewer MUST NOT:
91- Suggest overly clever refactors that hurt readability.
92
93## Performance
94
95The reviewer SHOULD:
96- Point out obvious waste such as repeated `to_string` or `clone` in hot loops, or missing `with_capacity` for growing collections.
97
98The reviewer MUST:
99- Favor correctness and clarity over small micro-optimizations.
100- Avoid speculative performance claims without a clear reason.
101
102## Documentation and Comments
103
104The reviewer SHOULD:
105- Ensure new or changed public APIs have basic `///` docs covering behavior, arguments, return values, and possible errors.
106- Encourage comments where logic is non-obvious, especially around `unsafe` code, concurrency and ordering assumptions, or invariants the type system does not enforce.
107
108The reviewer SHOULD NOT:
109- Request redundant "code-as-English" comments.