Advanced Rust code analysis and correction system with comprehensive error prevention, quality enforcement, and multi-stage validation. Provides direct guidance for compilation errors, safety issues, and code organization while maintaining consistency with Rustfmt and Clippy standards.
An advanced Rust code analysis and correction system that provides comprehensive error prevention, code quality enforcement, and automated validation across compilation, safety, testing, and style dimensions.
This skill transforms your coding assistant into a Rust expert that:
Run validation commands in this order:
1. **cargo check** (Priority 1) - Verify compilation before and after each change
2. **cargo clippy** (Priority 2) - Detect safety issues and common mistakes
3. **cargo test** (Priority 3) - Validate functionality (unit, integration, doc tests)
4. **cargo fmt -- --check** (Priority 4) - Ensure style consistency
Before making ANY code modification:
After each change:
Address errors in this order:
1. **Build errors** (compilation failures)
2. **Safety issues** (clippy warnings, unsafe code)
3. **Test failures** (unit/integration/doc tests)
4. **Style issues** (formatting, conventions)
Provide code suggestions as minimal Rust code blocks:
```rust
// Your corrected code here
// Maintain indentation and preserve comments
```
**Constraints:**
**Never remove unused code.** Instead:
For unused imports:
For unused functions:
For unused modules:
Place constants below imports using SCREAMING_SNAKE_CASE:
```rust
use std::time::Duration;
// Configuration constants
const TIMEOUT_SECONDS: u64 = 30;
const MAX_RETRIES: usize = 3;
const DEFAULT_BUFFER_SIZE: usize = 8192;
// Business logic constants
const MIN_PASSWORD_LENGTH: usize = 8;
```
Replace all magic numbers with named constants:
All public items must include doc comments with:
Inline comments (using `//`) for non-obvious logic.
For implementations, document:
Prefer `Result<T, E>` over panic:
```rust
// Create custom error types per module
#[derive(Debug)]
pub enum MyModuleError {
InvalidInput(String),
IoError(std::io::Error),
}
impl std::error::Error for MyModuleError {}
// Use ? operator for propagation
fn process() -> Result<(), MyModuleError> {
let data = read_data()?;
validate(data)?;
Ok(())
}
```
Reference modules using standardized patterns:
```rust
// Module imports
use crate::module_name::Type;
use super::parent_module::Item;
use self::nested::Function;
// Module declarations
mod utils;
pub mod api;
mod internal { /* ... */ }
```
Refer to modules in documentation as: `@module.rs`, `@lib.rs`, `@mod.rs`
Provide 2-5 actionable recommendations per error:
For unsafe code:
**Error:** Expected `String`, found `&str`
**Fix:**
```rust
// Convert &str to String using .to_string()
let name: String = user_input.to_string();
```
**Warning:** Unused import `std::collections::HashMap`
**Fix:**
```rust
use std::collections::HashMap;
// Create utility function using the import
fn create_cache() -> HashMap<String, i32> {
HashMap::new()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cache_creation() {
let cache = create_cache();
assert_eq!(cache.len(), 0);
}
}
```
**Before:**
```rust
if password.len() < 8 {
return Err("Password too short");
}
```
**After:**
```rust
// Minimum password length for security compliance
const MIN_PASSWORD_LENGTH: usize = 8;
if password.len() < MIN_PASSWORD_LENGTH {
return Err("Password too short");
}
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/rust-eze-debugger-x1g9mx/raw