Fix Clippy Warnings
Testing & Qualityfix-clippy-warningsFix Clippy Warnings is an Agent Skill for testing & quality published in the torrust/torrust-tracker repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Guide for fixing Rust Clippy warnings in the torrust-tracker project. Covers proper application of clippy suggestions, when to add allowances, and how to document exceptions. Use when asked to fix clippy warnings, improve code quality, or resolve linter issues. Triggers on "fix clippy", "clippy warnings", "rust code quality", or "linting issues".
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/torrust/torrust-tracker/blob/HEAD/.github/skills/dev/rust-code-quality/fix-clippy-warnings/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/fix-clippy-warnings, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Fix Clippy Warnings
This skill guides you through the proper handling of Rust Clippy warnings in the Torrust Tracker project.
Clippy Philosophy
Always prefer fixing clippy warnings with the suggested approach rather than adding #[allow(...)] attributes. Clippy warnings are designed to improve code quality, readability, and maintainability.
When to Apply Clippy Suggestions
✅ Apply Suggested Fixes
When clippy suggests a specific code change that improves quality:
- Use
as_chunks::<N>()instead ofchunks_exact(N)(as we did in SI-4) - Use
#[allow(clippy::explicit_iter_loop)]instead ofiter()when it's more concise - Apply any other suggestion that improves code quality
⚠️ When to Add Allowances
Only add #[allow(...)] when:
- The suggestion is not applicable to the specific use case
- The suggestion would break existing functionality or API
- The suggestion is temporarily ignored during a refactoring phase
- The suggestion is not yet supported in the current Rust version
How to Document Exceptions
When adding #[allow(...)] attributes, always include a clear comment explaining why:
// This is a temporary workaround during refactoring of the announce response parser
// TODO: Remove this allowance when the parser is fully refactored
#[allow(clippy::unnecessary_wraps)]
fn parse_announce_response(data: &[u8]) -> Result<Response, ParseError> {
// implementation
}
Common Clippy Patterns
Pattern 1: chunks_exact → as_chunks
Before:
for chunk in bytes.chunks_exact(6) {
// process 6-byte chunks
}
After:
let (chunks, remainder) = bytes.as_chunks::<6>();
if !remainder.is_empty() {
return Err(ParseError::InvalidChunkSize);
}
for chunk in chunks.iter() {
// process 6-byte chunks
}
Pattern 2: Explicit Iterator Loop
Before:
for item in items.iter() {
// process item
}
After:
for item in &items {
// process item
}
Clippy Workflow
- Identify the warning: Run
linter clippyto see specific clippy errors - Apply suggestion: Try the suggested fix first
- Verify functionality: Ensure the change doesn't break existing behavior
- Document exceptions: Add clear comments for any allowances
- Run full linters: Confirm
linter allpasses
Related Skills
run-linters- Run all code quality checkscommit-changes- Commit changes with proper conventions