Skip to content

chore: suppress all Linux build warnings (192 → 0)#577

Merged
H-Chris233 merged 3 commits into
Open-Less:betafrom
aeoform:chore/suppress-linux-build-warnings
Jun 3, 2026
Merged

chore: suppress all Linux build warnings (192 → 0)#577
H-Chris233 merged 3 commits into
Open-Less:betafrom
aeoform:chore/suppress-linux-build-warnings

Conversation

@aeoform
Copy link
Copy Markdown
Contributor

@aeoform aeoform commented Jun 2, 2026

User description

Summary

Linux build 从 192 个警告降至 0。

Approach

20+ 个源文件顶部加 #![cfg_attr(target_os = "linux", allow(dead_code, unused_variables))]。这些警告是 Linux 构建下的跨平台死代码(Windows IME、macOS 权限、Sherpa ASR、剪贴板恢复等),在其他平台上仍然使用,Linux 静默即可。

Manual fixes

  • coordinator.rs — 删掉未使用的 handle_pressed/handle_released 引用;#[cfg] 包裹 Linux 胶囊死路径
  • insertion.rs#[cfg(not(target_os = "linux"))] 包裹 Linux 永不执行的剪贴板回退表达式

Verification

cargo build --lib 2>&1 | grep "warning:" | wc -l  # 0
tsc --noEmit                                      # clean

🤖 Generated with Claude Code


PR Type

Enhancement, Bug fix


Description

  • Suppress 192 Linux build warnings with cfg_attr allow attributes

  • Fix manual warnings: unreachable code in coordinator.rs & insertion.rs

  • Restore cross-platform imports broken by cargo fix --broken-code


File Walkthrough

Relevant files
Bug fix
3 files
coordinator.rs
Wrap capsule emit with non-Linux cfg and add cfg_attr       
+4/-0     
insertion.rs
Add cfg gate for clipboard fallback and restore parameter names
+4/-2     
test_run.rs
Gate model_dir import behind cfg(target_os = "macos")       
+4/-1     
Enhancement
17 files
cache.rs
Add cfg_attr allowing unused_imports & unused_variables   
+1/-0     
lib.rs
Add cfg_attr allowing unused_imports & unused_variables   
+1/-0     
selection.rs
Add cfg_attr allowing unused_imports & unused_variables   
+1/-0     
frame.rs
Add cfg_attr to suppress dead_code/unused_variables           
+1/-0     
foundry_provider.rs
Extend existing allow to include unused_variables               
+1/-1     
foundry_runtime.rs
Add cfg_attr to suppress unused warnings                                 
+1/-0     
sherpa.rs
Add allow for dead_code, unused_imports, unused_variables
+1/-0     
sherpa_download.rs
Add allow for dead_code, unused_imports, unused_variables
+1/-0     
sherpa_provider.rs
Add allow for dead_code, unused_imports, unused_variables
+1/-0     
sherpa_runtime.rs
Add allow for dead_code, unused_imports, unused_variables
+1/-0     
volcengine.rs
Add cfg_attr to suppress dead_code/unused_variables           
+1/-0     
commands.rs
Add cfg_attr to suppress dead_code/unused_variables           
+1/-0     
hotkey.rs
Add cfg_attr to suppress dead_code                                             
+1/-0     
linux_fcitx.rs
Add cfg_attr to suppress dead_code/unused_variables           
+1/-0     
permissions.rs
Add cfg_attr to suppress dead_code/unused_variables           
+1/-0     
persistence.rs
Add cfg_attr to suppress dead_code/unused_variables           
+1/-0     
polish.rs
Add cfg_attr to suppress dead_code/unused_variables           
+1/-0     
Additional files
7 files
download.rs +1/-1     
types.rs +1/-0     
unicode_keystroke.rs +1/-0     
windows_ime_ipc.rs +1/-0     
windows_ime_profile.rs +1/-0     
windows_ime_protocol.rs +1/-0     
windows_ime_session.rs +1/-0     

Add #[cfg_attr(target_os = "linux", allow(dead_code, unused_variables))]
to 20+ source files where Linux builds see platform-specific dead code
(Windows IME, macOS permissions, Sherpa ASR, clipboard restore, etc.).
Also manually fix 3 real warnings: unused imports in coordinator.rs,
unreachable expression in insertion.rs.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

PR Reviewer Guide 🔍

(Review updated until commit 8d38681)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ No major issues detected

Restore handle_pressed/handle_released imports and window/show_capsule/
visible/audio_timeout/duration_ms variable names that cargo fix renamed
with _ prefix. These are used on macOS/Windows but the _ prefix broke
the builds. Add platform-gated import for model_dir in test_run.rs.

Expand cfg_attr allow lists to cover unused_imports and unused_variables
where needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Persistent review updated to latest commit b4d0f1e

Restore std::path::Path, std::sync::Arc, parking_lot::Mutex, anyhow::Result,
std::time::{Duration, Instant} imports in cache.rs, PhysicalPosition/PhysicalSize
in lib.rs, and std::time::Duration in selection.rs. These were removed by
cargo fix --broken-code because they appear unused on Linux but are needed
on macOS and Windows.

Add unused_imports to cfg_attr allow lists so future cargo fix runs on
Linux won't strip cross-platform imports again.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

Persistent review updated to latest commit 8d38681

@appergb
Copy link
Copy Markdown
Collaborator

appergb commented Jun 3, 2026

@claude 他这个更改真实有用吗?改得怎么样?opus 4.7

@claude
Copy link
Copy Markdown

claude Bot commented Jun 3, 2026

Claude finished @appergb's task in 1m 38s —— View job


PR #577 代码审查

  • 读取关键变更文件
  • 分析方案的有效性和质量
  • 给出综合评价

结论:有用,做得尚可,有几个小瑕疵


有用吗?

是的,实际有用。 192 个警告 → 0 是真实价值:

  • 真正的警告淹没在噪音里不容易发现(警告疲劳)
  • CI 日志更难阅读
  • 对 Linux 构建的代码质量信号改善明显

做得怎么样?

手工修复部分(做得好)

coordinator.rsinsertion.rstest_run.rs 这三个文件的改动是语义正确的,用 #[cfg] 真正地屏蔽掉 Linux 永远走不到的代码路径,而不是单纯压制编译器:

  • coordinator.rs#[cfg(not(target_os = "linux"))] 包裹胶囊窗口逻辑完全合理——Linux 走 fcitx5 路径,根本不操作胶囊窗口。
  • insertion.rs#[cfg(not(target_os = "linux"))] 包裹 insert_with_clipboard_restore 调用 + 把 _restore_clipboard_after_paste 改回无下划线,是正确的做法。
  • test_run.rs:把 model_dir import 限制在 #[cfg(target_os = "macos")] 是真正的修复。

批量 cfg_attr 部分(可接受但较粗糙)

20+ 个文件顶部加 #![cfg_attr(target_os = "linux", allow(dead_code, unused_variables))] 是一把大扫帚:

  • 优点:简单、统一、代码改动最小
  • 缺点:掩盖了本应用 #[cfg(target_os = "windows")] 等属性在模块级隔离的代码。例如 windows_ime_ipc.rswindows_ime_protocol.rs 等文件本质上是 Windows 专用代码,理想做法是在 mod 声明处加 #[cfg(target_os = "windows")],而非在每个文件内压制警告。不过这需要更大规模重构,作为 chore PR 不强求。

小瑕疵

1. sherpa.rs 没有 cfg_attr 限定(不一致)

// sherpa.rs — 全平台生效
#![allow(dead_code, unused_imports, unused_variables)]

// 其他文件 — 仅 Linux 生效
#![cfg_attr(target_os = "linux", allow(dead_code, unused_variables))]

sherpa.rs 用的是无条件 allow,在 macOS/Windows 上也静默了这些警告,与整个 PR 的策略不一致。也许是有意为之(该文件已有 Windows-only 死代码注释),但最好对齐为 cfg_attr。Fix this →

2. download.rs_total_chunks

- let total_chunks = chunks.len();
+ let _total_chunks = chunks.len();

改成下划线前缀说明这个变量确实没用,那为什么还要计算它?直接删掉更干净。Fix this →

3. 两个补救 commit 暴露了流程问题

fix(ci): restore variables broken by cargo fix --broken-codefix(ci): restore macOS/Windows imports removed by cargo fix --broken-code 说明初始方案用了 cargo fix --broken-code,把跨平台变量和 import 都破坏了,再手动修回来。这个流程可以改进:cargo fix --broken-code 对跨平台代码库不安全,应直接手工处理或先在 Linux 环境验证。


综合评分

维度 评价
目标达成 ✅ 192 → 0 警告,完成
手工修复质量 ✅ 语义正确,是真正的修复
批量压制质量 ⚠️ 可接受,但粒度较粗
一致性 ⚠️ sherpa.rs 策略不同
代码整洁 ⚠️ _total_chunks 是代码异味

总体:B+。 作为 chore PR 完全可以合入,手工修复部分质量不错,批量 cfg_attr 是务实选择。sherpa.rs 的不一致和 _total_chunks 是可选的跟进优化项。

@H-Chris233 H-Chris233 merged commit 63d3e16 into Open-Less:beta Jun 3, 2026
4 checks passed
@aeoform aeoform deleted the chore/suppress-linux-build-warnings branch June 3, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants