पाठ 25 / 25
A Rust Code Review Checklist
Common issues to look for.
Questions to ask
Does the code compile without warnings under clippy and pass rustfmt? Are functions taking borrowed parameters (&str, &[T]) where they do not need ownership? Are clones deliberate? Are errors returned as Result with useful types, with unwrap reserved for impossible cases and documented with expect? Are matches exhaustive without lazy catch-alls on your own enums? Is shared state across threads Arc plus Mutex or channels, with short lock scopes? Are integer conversions checked? Are there unit and doc tests?
The checklist
Use it in code reviews.
[ ] cargo clippy -- -D warnings and cargo fmt --check pass
[ ] borrowed parameters (&str, &[T]) unless ownership is needed
[ ] clones deliberate, not used to silence the borrow checker
[ ] Result for recoverable errors; ? to propagate; expect("why") over unwrap
[ ] exhaustive matches on own enums (no lazy _ arms)
[ ] checked / try_from conversions instead of lossy as casts
[ ] Arc + Mutex / channels across threads; short lock scopes
[ ] no blocking calls inside async tasks
[ ] unit tests incl. edge cases; doc tests for public APIs
[ ] unsafe blocks justified and documented (if any)Treat warnings as errors in CI
cargo clippy -- -D warnings keeps new warnings from piling up.
त्वरित जाँच: Which item belongs on a Rust review checklist?
- Clone every value to avoid borrow errors
- Use unwrap everywhere for brevity
- Use try_from or checked conversions instead of lossy as casts
- Share Rc between threads
Answer
Use try_from or checked conversions instead of lossy as casts — Safe, idiomatic, tested.