Prompt file imported from adzkar/badminton-tournament-api (
.windsurf/workflows/handle-warnings.md). Copyright stays with the author.
Workflow: Handle Rust Warnings
This workflow guides you through identifying, analyzing, and fixing Rust compiler warnings.
Step 0 — Identify Warnings
Run cargo check to see all current warnings:
cargo check
Common warning types:
unused_imports- Imports that are not useddead_code- Functions, structs, or fields that are never usedunused_variables- Variables that are declared but not read
Step 1 — Analyze Each Warning
For each warning, determine the appropriate action:
1a. Remove the code
Remove when:
- The code is truly unused and serves no purpose
- It's a leftover from refactoring
- It's a duplicate of something else
Examples:
- Unused imports in prelude files
- Error variants that are never constructed
- Dead functions that were replaced
1b. Add #[allow(dead_code)] with TODO
Add allow when:
- The code is part of a public API or structure
- The code is used in a different layer (e.g., domain model field used in infrastructure)
- The code is generated and should not be modified
- The code will be used in the future (with a clear TODO explaining why)
Always add a TODO comment explaining:
- Why the code exists
- Where/how it's used
- When it might be used in the future
Example:
// TODO: Field is used in infrastructure layer mapping (sea_tournament_repository.rs) but not directly in domain model
#[allow(dead_code)]
pub deleted_at: Option<DateTime<Utc>>,
Step 2 — Search for Usage
Before removing code, verify it's truly unused:
# Search for the identifier across the codebase
grep -r "IdentifierName" src/
For prelude re-exports, check if anything imports from the prelude:
grep -r "use.*prelude" src/
For error variants, check if they're ever constructed:
grep -r "AppError::VariantName" src/
Step 3 — Apply Fixes
Removing unused imports
Simply delete the import line.
Removing unused error variants
Remove both:
- The variant definition in the enum
- The HTTP status mapping in the
IntoResponseimplementation
Adding allow attributes
Add the attribute above the item with a TODO comment.
Step 4 — Verify
After making changes:
cargo check
Ensure:
- No warnings remain
- Code compiles successfully
- No new errors were introduced
Common Patterns in This Project
Prelude Pattern
- Issue: Entity re-exports in
src/infrastructure/database/entities/prelude.rsmay be unused - Fix: Remove if code uses direct imports instead of prelude
- Check: Search for
use.*preludeto see if prelude is used
Domain Model Fields
- Issue: Fields like
deleted_atin domain models triggerdead_codewarnings - Fix: Add
#[allow(dead_code)]with TODO explaining infrastructure layer usage - Reason: Domain models are mapped to/from SeaORM entities in infrastructure layer
Error Variants
- Issue: Error variants defined but never constructed
- Fix: Remove both the variant and its HTTP mapping
- Check: Search for
AppError::VariantNameusage
Constraints
- Never suppress warnings without understanding why they exist
- Always add TODO comments when using
#[allow(...)] - Prefer removal over suppression when code is truly unused
- Verify usage with grep before removing anything
- Run
cargo checkafter every change to verify the fix