rust-build
Fix Rust build errors, borrow checker issues, and dependency problems incrementally. Invokes the rust-build-resolver agent for minimal, surgical fixes.
Rust Build and Fix
This command invokes the rust-build-resolver agent to incrementally fix Rust build errors with minimal changes.
What This Command Does
- Run Diagnostics: Execute
cargo check,cargo clippy,cargo fmt --check - Parse Errors: Identify error codes and affected files
- Fix Incrementally: One error at a time
- Verify Each Fix: Re-run
cargo checkafter each change - Report Summary: Show what was fixed and what remains
When to Use
Use /rust-build when:
cargo buildorcargo checkfails with errorscargo clippyreports warnings- Borrow checker or lifetime errors block compilation
- Cargo dependency resolution fails
- After pulling changes that break the build
Diagnostic Commands Run
# Primary build checkcargo check 2>&1
# Lints and suggestionscargo clippy -- -D warnings 2>&1
# Formatting checkcargo fmt --check 2>&1
# Dependency issuescargo tree --duplicates
# Security audit (if available)if command -v cargo-audit >/dev/null; then cargo audit; else echo "cargo-audit not installed"; fiExample Session
User: /rust-build
Agent:# Rust Build Resolution
## Initial Diagnostics
```bash$ cargo checkerror[E0502]: cannot borrow `map` as mutable because it is also borrowed as immutable --> src/service/cache.rs:25:5error[E0308]: mismatched types --> src/handler/api.rs:42:12error[E0425]: cannot find value `db` in this scope --> src/handler/api.rs:58:9```
Errors found: 3
## Fix 1: Borrow Checker Error
File: src/service/cache.rs:25Error: E0502 — cannot borrow `map` as mutable because also borrowed as immutableCause: Immutable borrow still active during mutable insert
```rust// Changed: restructured to end immutable borrow before mutable accessif !map.contains_key("key") { map.insert("key".into(), default);}```
```bash$ cargo check# 2 errors remaining```
## Fix 2: Type Mismatch
File: src/handler/api.rs:42Error: E0308 — mismatched types: expected `usize`, found `&str`
```rust// Changedlet count = params.get("count");// Tolet count: usize = params.get("count") .and_then(|s| s.parse().ok()) .unwrap_or(0);```
```bash$ cargo check# 1 error remaining```
## Fix 3: Unresolved Name
File: src/handler/api.rs:58Error: E0425 — cannot find value `db` in this scopeCause: Missing import
```rust// Addeduse crate::db;```
```bash$ cargo check# Build successful!```
## Final Verification
```bash$ cargo clippy -- -D warnings# No warnings
$ cargo testrunning 6 teststest service::cache::tests::test_insert ... oktest service::cache::tests::test_get ... oktest handler::api::tests::test_parse_count ... oktest handler::api::tests::test_missing_count ... oktest handler::api::tests::test_db_import ... oktest handler::api::tests::test_response ... ok
test result: ok. 6 passed; 0 failed; 0 ignored```
## Summary
| Metric | Count ||--------|-------|| Build errors fixed | 3 || Clippy warnings fixed | 0 || Files modified | 2 || Remaining issues | 0 |
Build Status: SUCCESSCommon Errors Fixed
| Error | Typical Fix |
|---|---|
cannot borrow as mutable | Restructure to end immutable borrow first; clone only if justified |
does not live long enough | Use owned type or add lifetime annotation |
cannot move out of | Restructure to take ownership; clone only as last resort |
mismatched types | Add .into(), as, or explicit conversion |
trait X not implemented | Add #[derive(Trait)] or implement manually |
unresolved import | Add to Cargo.toml or fix use path |
cannot find value | Add import or fix path |
Fix Strategy
- Build errors first - Code must compile
- Clippy warnings second - Fix suspicious constructs
- Formatting third -
cargo fmtcompliance - One fix at a time - Verify each change
- Minimal changes - Don’t refactor, just fix
Stop Conditions
The agent will stop and report if:
- Same error persists after 3 attempts
- Fix introduces more errors
- Requires architectural changes
- Borrow checker error requires redesigning data ownership
Related Commands
/rust-test- Run tests after build succeeds/rust-review- Review code qualityverification-loopskill - Full verification loop
Related
- Agent:
agents/rust-build-resolver.md - Skill:
skills/rust-patterns/