From 22e0c70b9008090e56008f0f67b2f4ed204568a4 Mon Sep 17 00:00:00 2001 From: JoeAllen <2494136784@qq.com> Date: Wed, 30 Sep 2026 13:12:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(cross-platform):=20set=5Ftopmost/sample=20?= =?UTF-8?q?=E6=94=B9=E5=B1=9E=E6=80=A7=20cfg=20=E5=88=86=E6=B4=BE=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9D=9E=20Windows=20=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cfg!() 只是运行时常量,其分支永远参与类型检查 —— 非 Windows 下 sample_windows / set_topmost_windows 被属性 cfg 移除后调用点报 E0599 方法不存在(Linux CI Test job 第二跑暴露)。改为 #[cfg] 属性块分派,两条路径各平台上只有一个参与编译。 --- gpui-app/src/platform.rs | 13 ++++++++++--- gpui-app/src/sysmon.rs | 12 +++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gpui-app/src/platform.rs b/gpui-app/src/platform.rs index 8788b08..1556d62 100644 --- a/gpui-app/src/platform.rs +++ b/gpui-app/src/platform.rs @@ -2,10 +2,17 @@ /// 窗口置顶 / 取消置顶。返回是否成功(非 Windows 或句柄不可得为 false)。 pub fn set_topmost(window: &gpui_kit::Window, topmost: bool) -> bool { - if !cfg!(target_os = "windows") { - return false; + // 属性 cfg 分派而非 cfg!() 运行时判断:非 Windows 下 set_topmost_windows + // 被 cfg 移除,cfg! 分支仍参与编译会报方法不存在(CI Test job 实测暴露) + #[cfg(target_os = "windows")] + { + set_topmost_windows(window, topmost) + } + #[cfg(not(target_os = "windows"))] + { + let _ = (window, topmost); + false } - set_topmost_windows(window, topmost) } #[cfg(target_os = "windows")] diff --git a/gpui-app/src/sysmon.rs b/gpui-app/src/sysmon.rs index 2edc9f1..956f4c1 100644 --- a/gpui-app/src/sysmon.rs +++ b/gpui-app/src/sysmon.rs @@ -42,10 +42,16 @@ impl Sampler { /// 采样一次;CPU 占用首次采样为 0(无差分基准)。 pub fn sample(&mut self) -> Option { - if !cfg!(target_os = "windows") { - return Some(Sample::default()); + // 属性 cfg 分派而非 cfg!() 运行时判断:非 Windows 下 sample_windows + // 被 cfg 移除,cfg! 分支仍参与编译会报方法不存在(CI Test job 实测暴露) + #[cfg(target_os = "windows")] + { + self.sample_windows() + } + #[cfg(not(target_os = "windows"))] + { + Some(Sample::default()) } - self.sample_windows() } #[cfg(target_os = "windows")]