agentleFS
maxenkomaxenko/claude-skills/rust-warn-fix/SKILL.md

rust-warn-fix

Skill1 starsChanged 4 months agoMITView on GitHub

Analyzes all Rust compiler and Clippy warnings, then intelligently fixes or silences each one using expert judgment. Use when user says 'fix warnings', 'clean up warnings', 'resolve clippy', 'zero warnings', 'handle warnings', 'warning cleanup', or when Rust build output shows warnings. Also use proactively when cargo build/clippy output contains warnings during development. Do NOT use for adding new lint rules, configuring CI pipelines, or Cargo.toml lint setup.

The file

Show its rules and text

We split this skill into the rules it gives an agent

24 rules. About 0 are common, 10 are distinctive, and 14 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 14

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Fix first, silence only with justification: Every silenced warning is technical debt with an expiration date.

    line 14
  2. Distinctive:

    If provided, it narrows scope to a specific file path, module name, or lint name.

    line 20
  3. Distinctive:

    Check project structure before running anything:

    line 26
  4. Very specific:

    If [workspace] is present and $ARGUMENTS names a specific package, use cargo clippy -p <package> throughout.

    line 33
  5. Very specific:

    If the project has mutually exclusive features (look for compile_error!

    line 34
  6. Very specific:

    Add --all-features only if the project supports enabling all features simultaneously.

    line 42
  7. Distinctive:

    If clippy fails with compilation errors (not warnings), stop.

    line 44
  8. Very specific:

    If $ARGUMENTS specifies a file or module, focus on warnings from that scope.

    line 46
  9. Very specific:

    If cargo check fails after auto-fix, revert the broken changes (git checkout -- <file>) and fix those warnings manually instead.

    line 62
  10. Distinctive:

    After all changes, confirm zero warnings:

    line 76
  11. Distinctive:

    If new warnings appeared (fixing one can reveal another), repeat from Step 3.

    line 82
  12. Very specific:

    If thorough analysis confirms a false positive, document why with a // SAFETY: or // NOTE: comment and use #[expect] with a detailed reason.

    line 160
  13. Very specific:

    Narrowest scope possible: Put #[expect] on the specific item, not the module or crate.

    line 180
  14. Distinctive:

    For multiple items: if 3+ items in the same module need the same suppression for the same reason, module-level is acceptable.

    line 182
  15. Very specific:

    If the project's MSRV is below 1.81 (check rust-version in Cargo.toml), #[expect] and the reason parameter are unavailable.

    line 186
  16. Very specific:

    When you see an unused_variables warning on a guard/lock/tempfile/handle, always prefix with _name, never replace with bare _.

    line 209
  17. Very specific:

    When variables are only used under certain #[cfg] flags:

    line 215
  18. Very specific:

    Test modules often accumulate unused_imports from glob imports:

    line 225
  19. Very specific:

    If the project uses [workspace.lints] in Cargo.toml, respect that configuration.

    line 236
  20. Distinctive:

    After all fixes are applied and verified, provide a concise summary: total warnings before/after, each fix or suppression with its file …

    line 242
  21. Distinctive:

    Only report warnings that actually appear in cargo output: Do not invent warnings.

    line 246
  22. Distinctive:

    Read the file before editing: Never guess at line numbers or code content.

    line 247
  23. Distinctive:

    If cargo clippy produces zero warnings, say so and stop: Do not manufacture work.

    line 248
  24. Very specific:

    Verify fixes compile: After editing, run cargo check to confirm no regressions.

    line 249

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Warning Fixer

You are an expert Rust developer who resolves compiler and Clippy warnings with forward-thinking judgment. ultrathink about each warning before acting — your goal is zero warnings through intelligent fixes, not blanket suppression.

Core Philosophy

Fix first, silence only with justification. Every silenced warning is technical debt with an expiration date. Every fixed warning is permanent improvement. When you silence, use #[expect] so the suppression self-destructs when no longer needed.

Input

The optional argument is: $ARGUMENTS

If provided, it narrows scope to a specific file path, module name, or lint name. If empty, process all warnings in the project.

Workflow

Step 0: Pre-flight

Check project structure before running anything:

# Detect workspace vs single crate, check MSRV
grep -E 'rust-version|edition|\[workspace\]' Cargo.toml
  • If [workspace] is present and $ARGUMENTS names a specific package, use cargo clippy -p <package> throughout.
  • If the project has mutually exclusive features (look for compile_error! in feature gates), do NOT use --all-features. Use default features or the feature set documented in the project's CI/README.

Step 1: Capture Warnings

cargo clippy --all-targets 2>&1

Add --all-features only if the project supports enabling all features simultaneously. Add --workspace for workspace projects when no specific package is targeted.

If clippy fails with compilation errors (not warnings), stop. Report the errors to the user — you cannot fix warnings in code that doesn't compile.

If $ARGUMENTS specifies a file or module, focus on warnings from that scope. If it specifies a lint name, filter to that lint.

Step 2: Try Automatic Fixes First

Let Clippy fix what it can machine-apply:

cargo clippy --fix --allow-dirty --allow-staged --all-targets 2>&1 || true

Verify the auto-fix didn't break anything — clippy --fix has known bugs where it generates code that doesn't compile:

cargo check 2>&1

If cargo check fails after auto-fix, revert the broken changes (git checkout -- <file>) and fix those warnings manually instead.

Then re-run to see what remains:

cargo clippy --all-targets 2>&1

Step 3: Categorize Each Remaining Warning

For every warning, classify it using the decision framework below, then apply the appropriate action.

Step 4: Verify

After all changes, confirm zero warnings:

cargo clippy --all-targets 2>&1

If new warnings appeared (fixing one can reveal another), repeat from Step 3. Continue until clean.


Decision Framework

For each warning, follow this priority order.

Tier 1: ALWAYS FIX (never silence these)

These have mechanical, objectively correct fixes. Apply directly.

WarningFix
unused_importsDelete the import line
unused_mutRemove mut keyword
unused_must_useHandle the Result/#[must_use] return — do not discard silently
while_trueReplace while true with loop
for_loops_over_falliblesConvert to if let Some(x) = ... (Option) or if let Ok(x) = ... (Result)
path_statementsRemove the bare path or use the value
unreachable_codeRemove dead code after the unreachable point
redundant_semicolonsRemove extra semicolons
non_snake_case / non_camel_case_types / non_upper_case_globalsRename to follow convention. Grep for all usages and update them. If it's a public API, check if renaming is safe.
clippy::needless_returnRemove explicit return, use tail expression
clippy::let_and_returnCollapse into tail expression
clippy::manual_mapUse .map()
clippy::single_matchConvert to if let
clippy::needless_borrowRemove &
clippy::redundant_closurePass the function directly (e.g., |x| foo(x) becomes foo)
clippy::bool_assert_comparisonUse assert!(x) or assert!(!x)
clippy::clone_on_copyRemove .clone() on Copy types
clippy::map_cloneUse .copied() or .cloned()
clippy::collapsible_ifMerge nested if into single condition
clippy::len_zeroUse .is_empty() instead of .len() == 0
clippy::needless_range_loopUse iterator instead of index loop

Tier 2: FIX WHEN SAFE (use judgment)

These require context awareness. Read the surrounding code before deciding.

WarningWhen to FixWhen to Silence
dead_codeRemove if truly unreachable and not part of a public API being built incrementallySilence if: public library API, FFI export, or incomplete feature under active development
unused_variablesPrefix with _ if binding is structurally required (destructuring, trait impls). Remove if it serves no purposeSilence only in trait impls where the signature is fixed and _name would be confusing
deprecatedMigrate to replacement API if straightforwardSilence with reason if migration requires significant refactoring or replacement is unstable
unused_assignmentsRemove if value is truly never readSilence if assignment exists for side effects or clarity
clippy::redundant_cloneRemove .clone() and verify compilation — this lint has known false positives (it's in the nursery category). Always run cargo check after removing a cloneSilence if removal causes borrow checker errors
clippy::too_many_argumentsRefactor into config/builder struct if there's a natural groupingSilence if function mirrors an external API or FFI boundary
clippy::type_complexityCreate a type aliasSilence if type is used once and an alias would reduce readability
clippy::cast_losslessUse .into() or Type::from()Silence in FFI or numeric-heavy code where cast chains are clearer
clippy::module_name_repetitionsRename if stutter is unhelpful (e.g., user::UserConfig to user::Config)Silence if full name is more discoverable or module is re-exported

Tier 3: SILENCE WITH #[expect] (legitimate suppressions)

Valid reasons to suppress rather than fix. Always use #[expect] with a reason.

  • FFI boundaries: Function signatures must match C headers exactly
  • Trait implementations: Required method signatures where params are intentionally unused
  • Serialization fields: Fields used only by serde/derive but appear "dead" to the compiler
  • Platform-specific code: Variables used only under certain #[cfg] conditions
  • Performance-critical hot paths: Where Clippy's "cleaner" suggestion would add overhead
  • Deliberate patterns: Intentional unsafe, keeping code for clarity, matching external API naming

Tier 4: NEVER SILENCE (always investigate and fix)

These indicate bugs or potential undefined behavior. Silencing hides real problems.

  • unconditional_recursion — infinite recursion bug
  • unused_must_use — discarded error/value that must be handled
  • invalid_value — creating invalid memory states
  • dangling_pointers_from_locals / dangling_pointers_from_temporaries — use-after-free
  • const_item_mutation — mutation that has no effect
  • invalid_nan_comparisons — comparison that is always false
  • dropping_copy_types — drop that does nothing (logic error)
  • dropping_references — usually a logic error (intended to drop the owned value, not the reference). Investigate whether the code intended drop(owned_value) instead
  • Any warning in Clippy's correctness category
  • suspicious_double_ref_op — likely logic error with double references

If thorough analysis confirms a false positive, document why with a // SAFETY: or // NOTE: comment and use #[expect] with a detailed reason.


Suppression Syntax

Always prefer #[expect] over #[allow]. The expect attribute (stabilized in Rust 1.81) is strictly superior: it suppresses the warning like allow, but emits unfulfilled_lint_expectations when the warning disappears — meaning stale suppressions self-clean.

Correct form

#[expect(dead_code, reason = "public API surface — callers exist in downstream crates")]
pub fn exported_helper() { ... }

#[expect(clippy::too_many_arguments, reason = "mirrors the C API signature from libfoo.h")]
fn ffi_wrapper(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32, g: i32) { ... }

Scoping rules

  1. Narrowest scope possible. Put #[expect] on the specific item, not the module or crate.
  2. Never use #![allow(warnings)] or #![allow(clippy::all)] at crate root. This hides real problems.
  3. For multiple items: if 3+ items in the same module need the same suppression for the same reason, module-level is acceptable. Prefer per-item.

MSRV below 1.81

If the project's MSRV is below 1.81 (check rust-version in Cargo.toml), #[expect] and the reason parameter are unavailable. Use #[allow(lint)] with a code comment instead:

#[allow(dead_code)] // public API surface — callers exist in downstream crates
pub fn exported_helper() { ... }

Special Patterns

RAII guards: let _guard vs let _

This is a critical Rust footgun when handling unused variable warnings:

// Correct — named binding keeps the guard alive to end of scope
let _guard = lock.lock().unwrap();

// WRONG — standalone _ drops the guard immediately, releasing the lock
let _ = lock.lock().unwrap();

When you see an unused_variables warning on a guard/lock/tempfile/handle, always prefix with _name, never replace with bare _. The bare _ pattern drops the value at the end of the statement, not the scope.

Note: let _ = expr; is intentionally used to discard #[must_use] values — that's a different pattern and is fine when you genuinely want to ignore a Result.

Conditional compilation

When variables are only used under certain #[cfg] flags:

#[expect(unused_variables, reason = "used only on Windows for path normalization")]
let normalized = path.to_str().unwrap();
#[cfg(target_os = "windows")]
do_windows_thing(normalized);

Test modules

Test modules often accumulate unused_imports from glob imports:

#[cfg(test)]
mod tests {
    #[expect(unused_imports, reason = "glob import — not all parent items used in every test")]
    use super::*;
}

Workspace lint configuration

If the project uses [workspace.lints] in Cargo.toml, respect that configuration. Do NOT add per-item attributes that contradict workspace lint policy. If a workspace-level lint is set to deny, address the issue rather than silencing it per-item.


Reporting

After all fixes are applied and verified, provide a concise summary: total warnings before/after, each fix or suppression with its file location, lint name, and rationale. Flag any Tier 4 warnings that require the user's attention separately.

Anti-Hallucination Rules

  • Only report warnings that actually appear in cargo output. Do not invent warnings.
  • Read the file before editing. Never guess at line numbers or code content.
  • If cargo clippy produces zero warnings, say so and stop. Do not manufacture work.
  • Verify fixes compile. After editing, run cargo check to confirm no regressions.
  • Check usages before removing "dead" code. Grep for function/type/variable references first.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.