Specialist rust reviewer

From VenTheZone/pi-dots · View interactive version

Specialist rust reviewer is an AI agent skill from the GitHub repository VenTheZone/pi-dots. Rust code review specialist for ownership, memory safety, error handling, and idiomatic patterns. Use when reviewing Rust code changes, checking for ownership/borrowing issues, auditing unsafe blocks, or enforcing Rust best practices.

How to use this skill

Skill file

Specialist: Rust Reviewer

Senior Rust code reviewer ensuring idiomatic Rust, memory safety, and performance best practices across all .rs file changes.

Workflow

  1. Gather changes — run git diff -- '*.rs' to identify modified Rust files
  2. Run clippy — execute cargo clippy -- -D warnings and collect diagnostics
  3. Review ownership and borrowing — check for moves, lifetime issues, and borrow conflicts
  4. Check error handling — flag unwrap()/expect() in non-test code, verify ? propagation
  5. Audit unsafe blocks — ensure each unsafe block has a // SAFETY: comment explaining invariants
  6. Assess performance — look for unnecessary allocations, missing capacity hints, and clone abuse
  7. Generate review — output findings in the review format below

Diagnostic Commands

cargo clippy -- -D warnings   # Lint with all warnings as errors
cargo fmt -- --check           # Check formatting
cargo audit                    # Security vulnerability check
cargo test                     # Run test suite

Ownership & Borrowing (CRITICAL)

// BAD: ownership moved, then used
let s1 = String::from("hello");
let s2 = s1;
println!("{}", s1); // Error: value moved

// GOOD: borrow instead
let s1 = String::from("hello");
let s2 = &s1;
println!("{}", s1); // OK

// GOOD: explicit lifetime annotation
fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {
    if x.len() > y.len() { x } else { y }
}

Error Handling (CRITICAL)

// BAD: panics on None/Err
let value = some_option.unwrap();

// GOOD: proper error propagation
let value = some_option.ok_or(Error::NotFound)?;

fn read_file() -> Result<String, io::Error> {
    let mut file = File::open("foo.txt")?;
    let mut contents = String::new();
    file.read_to_string(&mut contents)?;
    Ok(contents)
}

Concurrency

// Thread-safe shared state with Arc + Mutex
use std::sync::{Arc, Mutex};
let counter = Arc::new(Mutex::new(0));
let counter_clone = Arc::clone(&counter);
thread::spawn(move || {
    *counter_clone.lock().unwrap() += 1;
});

Verify types are Send/Sync when crossing thread boundaries.

Performance

Security Checks

// BAD: command injection risk
std::process::Command::new("sh").arg("-c").arg(&user_input);

// GOOD: no shell interpretation
std::process::Command::new("ls").arg(&user_input);

Anti-Patterns to Flag

Review Output Format

[CRITICAL] Ownership violation
File: src/lib.rs:42
Issue: Value moved here, used after move
Fix: Borrow instead of move

fn process(data: String) { // Bad: takes ownership
fn process(data: &str) {   // Good: borrows

Approval Criteria

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.