6.1 KiB
Code Cleanup: Removing Unused Code Warnings
This document tracks unused code warnings and the proper way to fix them.
Strategy: NO #[allow(dead_code)] Bandaids
Instead, we either:
- USE IT - Create API endpoints or connect to existing flows
- REMOVE IT - Delete truly unused code
1. Channel Adapters (src/channels/mod.rs)
Status: KEEP - Used via trait dispatch
Issue: Trait methods marked as unused but they ARE used polymorphically.
Solution: These are false positives. The trait methods are called through dyn ChannelAdapter, so the compiler doesn't detect usage. Keep as-is.
ChannelAdapter::send_message()- Used by channel implementationsChannelAdapter::receive_message()- Used by channel implementationsChannelAdapter::get_channel_name()- Used by channel implementationsVoiceAdaptermethods - Used in voice processing flow
Action: Document that these are used via trait dispatch. No changes needed.
2. Meet Service (src/meet/service.rs)
Status: NEEDS API ENDPOINTS
Unused Methods:
MeetingService::join_room()MeetingService::start_transcription()MeetingService::get_room()MeetingService::list_rooms()
Solution: Add REST API endpoints in src/main.rs:
// Add to api_router:
.route("/api/meet/rooms", get(crate::meet::list_rooms_handler))
.route("/api/meet/room/:room_id", get(crate::meet::get_room_handler))
.route("/api/meet/room/:room_id/join", post(crate::meet::join_room_handler))
.route("/api/meet/room/:room_id/transcription", post(crate::meet::toggle_transcription_handler))
Then create handlers in src/meet/mod.rs that call the service methods.
3. Multimedia Service (src/bot/multimedia.rs)
Status: NEEDS API ENDPOINTS
Unused Methods:
MultimediaHandler::upload_media()MultimediaHandler::download_media()MultimediaHandler::generate_thumbnail()
Solution: Add REST API endpoints:
// Add to api_router:
.route("/api/media/upload", post(crate::bot::multimedia::upload_handler))
.route("/api/media/download/:media_id", get(crate::bot::multimedia::download_handler))
.route("/api/media/thumbnail/:media_id", get(crate::bot::multimedia::thumbnail_handler))
Create handlers that use the DefaultMultimediaHandler implementation.
4. Drive Monitor (src/drive_monitor/mod.rs)
Status: KEEP - Used internally
Issue: Fields and methods marked as unused but ARE used.
Reality Check:
DriveMonitoris constructed insrc/bot/mod.rs(line 48)- It's stored in
BotOrchestrator::mounted_bots - The
spawn()method is called to start the monitoring task - Internal fields are used within the monitoring loop
Action: This is a false positive. The struct is actively used. No changes needed.
5. Basic Compiler (src/basic/compiler/mod.rs)
Status: KEEP - Used by DriveMonitor
Issue: Structures marked as unused.
Reality Check:
BasicCompileris constructed insrc/drive_monitor/mod.rs(line 276)ToolDefinition,MCPTool, etc. are returned by compilation- Used for
.basfile compilation in gbdialog folders
Action: These are actively used. False positives from compiler analysis. No changes needed.
6. Zitadel Auth (src/auth/zitadel.rs)
Status: PARTIAL USE - Some methods need endpoints, some can be removed
Currently Unused:
verify_token()- Should be used in auth middlewarerefresh_token()- Should be exposed via/api/auth/refreshendpointget_user_workspace()- Called ininitialize_user_workspace()which IS usedUserWorkspacestruct - Created and used in workspace initialization
Action Items:
- Add auth middleware that uses
verify_token():
// src/auth/middleware.rs (new file)
pub async fn require_auth(
State(state): State<Arc<AppState>>,
headers: HeaderMap,
request: Request,
next: Next,
) -> Result<Response, StatusCode> {
// Extract and verify JWT using zitadel.verify_token()
}
- Add refresh endpoint:
// In src/auth/mod.rs
pub async fn refresh_token_handler(...) -> impl IntoResponse {
// Call zitadel.refresh_token()
}
- Add to routes:
.route("/api/auth/refresh", post(refresh_token_handler))
Methods to Remove:
extract_user_id_from_token()- Can be replaced with proper JWT parsing inverify_token()
7. Email Setup (src/package_manager/setup/email_setup.rs)
Status: KEEP - Used in bootstrap process
Issue: Methods marked as unused.
Reality Check:
EmailSetupis used in bootstrap/setup flows- Methods are called when setting up email server
- This is infrastructure code, not API code
Action: These are legitimately used during setup. False positives. No changes needed.
8. Config Structures (src/config/mod.rs)
Status: INVESTIGATE - May have unused fields
Unused Fields:
AppConfig::email- Check if email config is actually read- Various
EmailConfigfields
Action:
- Check if
AppConfig::from_database()actually reads these fields from DB - If yes, keep them
- If no, remove unused fields from the struct
9. Session/LLM Minor Warnings
These are small warnings in various files. After fixing the major items above, recheck diagnostics and clean up minor issues.
Priority Order
- Fix multimedia.rs field name bugs (blocking compilation)
- Add meet service API endpoints (most complete feature waiting for APIs)
- Add multimedia API endpoints
- Add auth middleware + refresh endpoint
- Document false positives (channels, drive_monitor, compiler)
- Clean up config unused fields
- Minor cleanup pass on remaining warnings
Rules
- ❌ NEVER use
#[allow(dead_code)]as a quick fix - ✅ CREATE API endpoints for unused service methods
- ✅ DOCUMENT false positives from trait dispatch or internal usage
- ✅ REMOVE truly unused code that serves no purpose
- ✅ VERIFY usage before removing - use
grepandfindto check references
Testing After Changes
After each cleanup:
cargo check
cargo test
cargo clippy
Ensure:
- All tests pass
- No new warnings introduced
- Functionality still works