rust-review
Comprehensive Rust code review for ownership, lifetimes, error handling, unsafe usage, and idiomatic patterns. Invokes the rust-reviewer agent.
Rust Code Review
This command invokes the rust-reviewer agent for comprehensive Rust-specific code review.
What This Command Does
- Verify Automated Checks: Run
cargo check,cargo clippy -- -D warnings,cargo fmt --check, andcargo test— stop if any fail - Identify Rust Changes: Find modified
.rsfiles viagit diff HEAD~1(orgit diff main...HEADfor PRs) - Run Security Audit: Execute
cargo auditif available - Security Scan: Check for unsafe usage, command injection, hardcoded secrets
- Ownership Review: Analyze unnecessary clones, lifetime issues, borrowing patterns
- Generate Report: Categorize issues by severity
When to Use
Use /rust-review when:
- After writing or modifying Rust code
- Before committing Rust changes
- Reviewing pull requests with Rust code
- Onboarding to a new Rust codebase
- Learning idiomatic Rust patterns
Review Categories
CRITICAL (Must Fix)
- Unchecked
unwrap()/expect()in production code paths unsafewithout// SAFETY:comment documenting invariants- SQL injection via string interpolation in queries
- Command injection via unvalidated input in
std::process::Command - Hardcoded credentials
- Use-after-free via raw pointers
HIGH (Should Fix)
- Unnecessary
.clone()to satisfy borrow checker Stringparameter where&strorimpl AsRef<str>suffices- Blocking in async context (
std::thread::sleep,std::fs) - Missing
Send/Syncbounds on shared types - Wildcard
_ =>match on business-critical enums - Large functions (>50 lines)
MEDIUM (Consider)
- Unnecessary allocation in hot paths
- Missing
with_capacitywhen size is known - Suppressed clippy warnings without justification
- Public API without
///documentation - Consider
#[must_use]on non-must_usereturn types where ignoring values is likely a bug
Automated Checks Run
# Build gate (must pass before review)cargo check
# Lints and suggestionscargo clippy -- -D warnings
# Formattingcargo fmt --check
# Testscargo test
# Security audit (if available)if command -v cargo-audit >/dev/null; then cargo audit; else echo "cargo-audit not installed"; fiExample Usage
User: /rust-review
Agent:# Rust Code Review Report
## Files Reviewed- src/service/user.rs (modified)- src/handler/api.rs (modified)
## Static Analysis Results- Build: Successful- Clippy: No warnings- Formatting: Passed- Tests: All passing
## Issues Found
[CRITICAL] Unchecked unwrap in Production PathFile: src/service/user.rs:28Issue: Using `.unwrap()` on database query result```rustlet user = db.find_by_id(id).unwrap(); // Panics on missing user```Fix: Propagate error with context```rustlet user = db.find_by_id(id) .context("failed to fetch user")?;```
[HIGH] Unnecessary CloneFile: src/handler/api.rs:45Issue: Cloning String to satisfy borrow checker```rustlet name = user.name.clone();process(&user, &name);```Fix: Restructure to avoid clone```rustlet result = process_name(&user.name);use_user(&user, result);```
## Summary- CRITICAL: 1- HIGH: 1- MEDIUM: 0
Recommendation: Block merge until CRITICAL issue is fixedApproval Criteria
| Status | Condition |
|---|---|
| Approve | No CRITICAL or HIGH issues |
| Warning | Only MEDIUM issues (merge with caution) |
| Block | CRITICAL or HIGH issues found |
Integration with Other Commands
- Use
/rust-testfirst to ensure tests pass - Use
/rust-buildif build errors occur - Use
/rust-reviewbefore committing - Use
/code-reviewfor non-Rust-specific concerns
Related
- Agent:
agents/rust-reviewer.md - Skills:
skills/rust-patterns/,skills/rust-testing/