# Compiler Warnings Cleanup Plan
**Created**: 2025-11-26
**Status**: In Progress
**Goal**: Zero warnings in all tests and code
---
## Summary
**Total Warnings**: ~65
**Categories**:
- Dead code (unused fields, structs, functions): ~55
- Unused imports: ~5
- Never constructed: ~5
**Strategy**: Fix by making code useful OR add `#[allow(dead_code)]` with justification
---
## Test Files with Warnings
### 1. tests/03_api_handler.rs (16 warnings)
**Issue**: Macro test examples that define structs/functions but don't call them
**Warnings**:
- CreateUserRequest, CreateUserResponse (never constructed)
- create_user function (never used)
- ListUsersQuery, User (never constructed)
- list_users (never used)
- UserResponse (never constructed)
- get_user (never used)
- SuccessResponse, ErrorResponse (never constructed)
- validate_data (never used)
- health_check (never used)
- ValidatedRequest (never constructed)
- register_user (never used)
- get_users, get_posts (never used)
**Fix Strategy**: These are testing macro expansion, not actual usage
- Option A: Add actual test calls
- Option B: Add `#[allow(dead_code)]` to test module with explanation
**Recommended**: Option B - These test macro expansion, not runtime behavior
```rust
#[cfg(test)]
#[allow(dead_code)] // Testing macro expansion, not runtime usage
mod test_api_handler_macro {
// ... existing code
}
```
---
### 2. tests/03_api_handler_simple.rs (4 warnings)
**Issue**: Similar to above - macro tests without calls
**Warnings**:
- health_check (never used)
- CreateRequest (never constructed)
- create_user (never used)
- status (never used)
**Fix Strategy**: Same as #1
```rust
#[cfg(test)]
#[allow(dead_code)] // Testing macro expansion
mod test_simple_handlers {
// ... existing code
}
```
---
### 3. tests/05_arch_integration.rs (3 warnings)
**Issue**: Test structs with unused fields
**Warnings**:
- User.name (never read)
- User.email (never read)
- Post.id (never read)
**Fix Strategy**: These fields ARE part of the test domain model
- Option A: Use the fields in assertions
- Option B: Prefix with `_` if truly test fixtures
- Option C: Add `#[allow(dead_code)]` if modeling architecture
**Recommended**: Option A - Add assertions that use these fields
```rust
#[test]
fn test_domain_layer() {
#[domain]
#[derive(Clone)]
struct User {
id: String,
name: String,
email: String,
}
let user = User {
id: "123".to_string(),
name: "Test".to_string(),
email: "test@example.com".to_string(),
};
// FIX: Add assertions
assert_eq!(user.id, "123");
assert_eq!(user.name, "Test");
assert_eq!(user.email, "test@example.com");
}
```
---
### 4. tests/05_arch_layers.rs (12 warnings)
**Issue**: Clean Architecture layer testing with unused types
**Warnings**:
- Multiple User structs (never constructed)
- UserRepository trait (never used)
- GetUserUseCase (never constructed)
- GetUserHandler (never constructed)
- Various methods (find, new) never used
**Fix Strategy**: These are testing layer markers, not functionality
- Add `#[allow(dead_code)]` to each test module
```rust
#[test]
fn test_domain_layer_marker() {
#[allow(dead_code)] // Testing #[domain] marker, not usage
#[domain]
struct User {
id: String,
email: String,
}
// This test validates the marker compiles
}
```
---
### 5. tests/06_cqrs_commands.rs (5 warnings)
**Issue**: Command handler tests with unused code
**Warnings**:
- CreateUserCommand.name (never read)
- CreateUserCommand (never constructed)
- UpdateUserCommand (never constructed)
- handle_create, handle_update (never used)
**Fix Strategy**: These test command handler macros
- Either use them OR mark as test-only
```rust
#[test]
fn test_command_handler_macro() {
#[allow(dead_code)] // Testing #[command_handler] macro expansion
#[command_handler]
async fn handle_create(_cmd: CreateUserCommand) -> Result<Vec<UserEvent>, String> {
Ok(vec![])
}
}
```
---
### 6. tests/06_cqrs_events.rs (4 warnings)
**Issue**: Event versioning tests with unused fields
**Warnings**:
- UserEvent::Deleted (never constructed)
- UserCreatedV1.version (never read)
- UserCreatedV2.user_id, email (never read)
- StreamUserEvent::Created.user_id (never read)
**Fix Strategy**: Test data that's part of the domain model
- Use the fields in assertions
```rust
#[test]
fn test_versioned_event() {
struct UserCreatedV1 {
version: u32,
user_id: String,
email: String,
}
let event = UserCreatedV1 {
version: 1,
user_id: "123".to_string(),
email: "test@example.com".to_string(),
};
// FIX: Assert fields are used
assert_eq!(event.version, 1);
assert_eq!(event.user_id, "123");
assert_eq!(event.email, "test@example.com");
}
```
---
### 7. tests/06_cqrs_integration.rs (5 warnings)
**Issue**: Integration test domain models with unused code
**Warnings**:
- UserEvent::Deleted (never constructed)
- User.id (never read)
- ArchUser (never constructed)
- ArchUserEvent::Created fields (never read)
- GetArchUserQuery.user_id (never read)
**Fix Strategy**: Add assertions or mark as test fixtures
---
### 8. tests/06_cqrs_queries.rs (1 warning)
**Issue**: User.id never read
**Fix**: Add assertion
```rust
let user = User { id: "123".to_string(), ... };
assert_eq!(user.id, "123"); // FIX
```
---
### 9. tests/06_cqrs_property.rs (1 warning)
**Issue**: User.id never read
**Fix**: Same as #8
---
### 10. tests/07_otel_integration.rs (2 warnings)
**Issue**: User.id, UserEvent::Created.user_id never read
**Fix**: Add assertions
---
### 11. tests/07_otel_tracing.rs (1 warning)
**Issue**: Unused import SpanRecorder
**Fix**: Either use it or remove it
```rust
// Current:
use allframe_core::otel::{traced, SpanRecorder};
// Option A: Use it
let recorder = SpanRecorder::new();
// Option B: Remove it
use allframe_core::otel::traced;
```
---
### 12. tests/02_di_container.rs (1 warning)
**Issue**: Counter.count never read
**Fix**: Add assertion
```rust
let counter = Counter { name: "test".to_string(), count: 0 };
assert_eq!(counter.count, 0); // FIX
```
---
## Fix Plan
### Phase 1: Macro Tests (tests with #[allow(dead_code)])
**Files**:
- tests/03_api_handler.rs
- tests/03_api_handler_simple.rs
- tests/05_arch_layers.rs
- tests/06_cqrs_commands.rs
**Action**: Add `#[allow(dead_code)]` to test modules that test macro expansion
**Justification**: These tests validate that macros compile correctly, not that code is used
---
### Phase 2: Add Assertions (tests where fields should be validated)
**Files**:
- tests/05_arch_integration.rs
- tests/06_cqrs_events.rs
- tests/06_cqrs_integration.rs
- tests/06_cqrs_queries.rs
- tests/06_cqrs_property.rs
- tests/07_otel_integration.rs
- tests/02_di_container.rs
**Action**: Add assertions that use the "unused" fields
**Justification**: These are domain models - fields should be validated
---
### Phase 3: Fix Unused Imports
**Files**:
- tests/07_otel_tracing.rs
**Action**: Remove or use SpanRecorder
---
## Implementation
### Step 1: Run Tests to Get Current State
```bash
```
---
### Step 2: Fix Macro Tests
**File: tests/03_api_handler.rs**
```rust
#[cfg(test)]
mod test_api_handler_macro {
use allframe_macros::api_handler;
// Testing macro expansion, not runtime usage
#[allow(dead_code)]
struct CreateUserRequest {
email: String,
name: String,
}
#[allow(dead_code)]
struct CreateUserResponse {
id: String,
email: String,
}
#[allow(dead_code)]
#[api_handler]
async fn create_user(req: CreateUserRequest) -> CreateUserResponse {
CreateUserResponse {
id: "123".to_string(),
email: req.email,
}
}
// ... rest of file
}
```
**Repeat for**:
- tests/03_api_handler_simple.rs
- tests/05_arch_layers.rs
- tests/06_cqrs_commands.rs
---
### Step 3: Add Assertions
**Example: tests/05_arch_integration.rs**
```rust
#[test]
fn test_domain_layer() {
#[domain]
#[derive(Clone)]
struct User {
id: String,
name: String,
email: String,
}
let user = User {
id: "123".to_string(),
name: "Test User".to_string(),
email: "test@example.com".to_string(),
};
// ADD THESE ASSERTIONS
assert_eq!(user.id, "123");
assert_eq!(user.name, "Test User");
assert_eq!(user.email, "test@example.com");
}
```
**Repeat pattern for all other test files**
---
### Step 4: Fix Imports
**File: tests/07_otel_tracing.rs**
```rust
// Remove unused import
use allframe_core::otel::traced;
// Removed: SpanRecorder
```
---
### Step 5: Verify
```bash
```
---
## Expected Outcome
**Before**:
- ~65 warnings
- Unclear which code is intentionally unused
- Noisy test output
**After**:
- 0 warnings
- Clear documentation (via `#[allow(dead_code)]` comments) of why code exists
- Clean test output
- Better test coverage (assertions validate domain models)
---
## Implementation Order
1. ✅ Document all warnings (this file)
2. ⏳ Phase 1: Macro tests (add `#[allow(dead_code)]`)
3. ⏳ Phase 2: Domain model tests (add assertions)
4. ⏳ Phase 3: Fix imports
5. ⏳ Verify zero warnings
6. ✅ Update CI/CD to enforce `-D warnings`
---
## CI/CD Enforcement
Add to `.github/workflows/test.yml`:
```yaml
- name: Check for warnings
run: cargo clippy --all-features -- -D warnings
- name: Test with warnings as errors
run: RUSTFLAGS="-D warnings" cargo test --all-features
```
This ensures NO warnings ever merge to main.
---
**Status**: Ready to implement
**Estimated Time**: 1-2 hours
**Priority**: P1 (should do before Phase 6)