Rust compiler diagnostics

From mkurman/zorai · View interactive version

Rust compiler diagnostics is an AI agent skill from the GitHub repository mkurman/zorai. Use when Rust code fails to compile, Clippy reports lints, borrow checker errors appear, lifetimes are unclear, or cargo diagnostics need systematic triage.

How to use this skill

Skill file

Rust Compiler Diagnostics

Use this skill to resolve Rust compiler and Clippy diagnostics without guessing.

Workflow

  1. Run the narrowest command that reproduces the diagnostic, usually cargo check -p <crate> or a focused test.
  2. Read the first real compiler error before secondary errors; later diagnostics are often consequences.
  3. Identify the ownership, lifetime, type, trait, macro, feature, or lint category involved.
  4. Inspect the definition site and the nearest caller before editing.
  5. Prefer changing API shape only when the current contract is the real cause.
  6. Re-run the same command after each fix, then broaden verification when the focused command is clean.

Borrow Checker Triage

Diagnostic Repair Examples

End A Borrow Before Mutation

// Avoid: `self.items` is immutably borrowed while mutating `self`.
if let Some(item) = self.items.get(id) {
    self.record_access(item.name());
}

// Prefer: extract the needed owned value, ending the borrow.
let name = self.items.get(id).map(|item| item.name().to_owned());
if let Some(name) = name {
    self.record_access(&name);
}

Move Out Of A Field Safely

if let Some(task) = self.pending_task.take() {
    task.cancel().await;
}

Use Option::take when a field must be moved out while leaving the struct in a valid state.

Fix Escaping Borrow In Spawned Tasks

// Avoid: `&self` cannot be moved into a 'static task.
tokio::spawn(async move {
    self.refresh().await;
});

// Prefer: clone the owned handle needed by the task.
let client = self.client.clone();
tokio::spawn(async move {
    client.refresh().await;
});

Clippy Triage

Prefer Targeted Allows

#[allow(clippy::too_many_arguments, reason = "constructor mirrors the wire protocol fields")]
pub fn from_wire(/* fields */) -> Self {
    // ...
}

References

Read references/error-triage.md for common diagnostic families and repair patterns.

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.