fix(cross-platform): set_topmost/sample 改属性 cfg 分派,修复非 Windows 编译

cfg!() 只是运行时常量,其分支永远参与类型检查 —— 非 Windows 下
sample_windows / set_topmost_windows 被属性 cfg 移除后调用点报
E0599 方法不存在(Linux CI Test job 第二跑暴露)。改为
#[cfg] 属性块分派,两条路径各平台上只有一个参与编译。
This commit is contained in:
2026-09-30 13:12:36 +08:00
parent 7bff64e477
commit 22e0c70b90
2 changed files with 19 additions and 6 deletions
+10 -3
View File
@@ -2,10 +2,17 @@
/// 窗口置顶 / 取消置顶。返回是否成功(非 Windows 或句柄不可得为 false)。 /// 窗口置顶 / 取消置顶。返回是否成功(非 Windows 或句柄不可得为 false)。
pub fn set_topmost(window: &gpui_kit::Window, topmost: bool) -> bool { pub fn set_topmost(window: &gpui_kit::Window, topmost: bool) -> bool {
if !cfg!(target_os = "windows") { // 属性 cfg 分派而非 cfg!() 运行时判断:非 Windows 下 set_topmost_windows
return false; // 被 cfg 移除,cfg! 分支仍参与编译会报方法不存在(CI Test job 实测暴露)
} #[cfg(target_os = "windows")]
{
set_topmost_windows(window, topmost) set_topmost_windows(window, topmost)
}
#[cfg(not(target_os = "windows"))]
{
let _ = (window, topmost);
false
}
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
+9 -3
View File
@@ -42,11 +42,17 @@ impl Sampler {
/// 采样一次;CPU 占用首次采样为 0(无差分基准)。 /// 采样一次;CPU 占用首次采样为 0(无差分基准)。
pub fn sample(&mut self) -> Option<Sample> { pub fn sample(&mut self) -> Option<Sample> {
if !cfg!(target_os = "windows") { // 属性 cfg 分派而非 cfg!() 运行时判断:非 Windows 下 sample_windows
return Some(Sample::default()); // 被 cfg 移除,cfg! 分支仍参与编译会报方法不存在(CI Test job 实测暴露)
} #[cfg(target_os = "windows")]
{
self.sample_windows() self.sample_windows()
} }
#[cfg(not(target_os = "windows"))]
{
Some(Sample::default())
}
}
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
fn sample_windows(&mut self) -> Option<Sample> { fn sample_windows(&mut self) -> Option<Sample> {