From 94c51c6ac958de75e31c50151714cb8988041ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=B1=B1=E9=A2=A8=E9=9C=B2?= Date: Fri, 29 Mar 2024 00:55:35 +0900 Subject: [PATCH] Windows: Enable clippy deny warnings (#9920) ~Waiting #9918~ Release Notes: - N/A --- crates/cli/src/main.rs | 2 +- crates/gpui/src/platform/test.rs | 2 -- crates/gpui/src/platform/test/platform.rs | 3 +- crates/gpui/src/platform/windows/display.rs | 8 ++--- crates/gpui/src/platform/windows/platform.rs | 4 +-- crates/gpui/src/platform/windows/window.rs | 33 +++++++++----------- crates/project/src/project_tests.rs | 4 ++- crates/terminal/src/pty_info.rs | 2 +- tooling/xtask/src/main.rs | 3 -- 9 files changed, 26 insertions(+), 35 deletions(-) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 8d3f91ef2a4ff1..9ae0ed0465b56d 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1,4 +1,4 @@ -#![cfg_attr(target_os = "linux", allow(dead_code))] +#![cfg_attr(any(target_os = "linux", target_os = "windows"), allow(dead_code))] use anyhow::{anyhow, Context, Result}; use clap::Parser; diff --git a/crates/gpui/src/platform/test.rs b/crates/gpui/src/platform/test.rs index 45948a1ba24753..c60233592886da 100644 --- a/crates/gpui/src/platform/test.rs +++ b/crates/gpui/src/platform/test.rs @@ -7,6 +7,4 @@ mod window; pub(crate) use dispatcher::*; pub(crate) use display::*; pub(crate) use platform::*; -#[cfg(target_os = "windows")] -pub(crate) use text_system::*; pub(crate) use window::*; diff --git a/crates/gpui/src/platform/test/platform.rs b/crates/gpui/src/platform/test/platform.rs index 649b74f7dd841c..8a595b2f615ff3 100644 --- a/crates/gpui/src/platform/test/platform.rs +++ b/crates/gpui/src/platform/test/platform.rs @@ -125,9 +125,8 @@ impl Platform for TestPlatform { #[cfg(target_os = "macos")] return Arc::new(crate::platform::mac::MacTextSystem::new()); - // todo("windows") #[cfg(target_os = "windows")] - unimplemented!() + return Arc::new(crate::platform::windows::WindowsTextSystem::new()); } fn run(&self, _on_finish_launching: Box) { diff --git a/crates/gpui/src/platform/windows/display.rs b/crates/gpui/src/platform/windows/display.rs index c721d305872100..64a641aebb35aa 100644 --- a/crates/gpui/src/platform/windows/display.rs +++ b/crates/gpui/src/platform/windows/display.rs @@ -33,12 +33,12 @@ impl WindowsDisplay { display_id, bounds: Bounds { origin: Point { - x: DevicePixels(size.left as i32), - y: DevicePixels(size.top as i32), + x: DevicePixels(size.left), + y: DevicePixels(size.top), }, size: Size { - width: DevicePixels((size.right - size.left) as i32), - height: DevicePixels((size.bottom - size.top) as i32), + width: DevicePixels(size.right - size.left), + height: DevicePixels(size.bottom - size.top), }, }, uuid, diff --git a/crates/gpui/src/platform/windows/platform.rs b/crates/gpui/src/platform/windows/platform.rs index ef1140081ff6e1..609749b98d075c 100644 --- a/crates/gpui/src/platform/windows/platform.rs +++ b/crates/gpui/src/platform/windows/platform.rs @@ -722,9 +722,7 @@ impl Platform for WindowsPlatform { (*credentials).CredentialBlobSize as usize, ) }; - let mut password: Vec = Vec::with_capacity(credential_blob.len()); - password.resize(password.capacity(), 0); - password.clone_from_slice(&credential_blob); + let password = credential_blob.to_vec(); unsafe { CredFree(credentials as *const c_void) }; Ok(Some((username, password))) } diff --git a/crates/gpui/src/platform/windows/window.rs b/crates/gpui/src/platform/windows/window.rs index c46dcb87ebf3d1..5adf8997012b92 100644 --- a/crates/gpui/src/platform/windows/window.rs +++ b/crates/gpui/src/platform/windows/window.rs @@ -68,12 +68,12 @@ impl WindowsWindowInner { ) -> Self { let monitor_dpi = unsafe { GetDpiForWindow(hwnd) } as f32; let origin = Cell::new(Point { - x: DevicePixels(cs.x as i32), - y: DevicePixels(cs.y as i32), + x: DevicePixels(cs.x), + y: DevicePixels(cs.y), }); let physical_size = Cell::new(Size { - width: DevicePixels(cs.cx as i32), - height: DevicePixels(cs.cy as i32), + width: DevicePixels(cs.cx), + height: DevicePixels(cs.cy), }); let scale_factor = Cell::new(monitor_dpi / USER_DEFAULT_SCREEN_DPI as f32); let input_handler = Cell::new(None); @@ -175,10 +175,10 @@ impl WindowsWindowInner { let bounds = self.display.borrow().clone().bounds(); StyleAndBounds { style, - x: bounds.left().0 as i32, - y: bounds.top().0 as i32, - cx: bounds.size.width.0 as i32, - cy: bounds.size.height.0 as i32, + x: bounds.left().0, + y: bounds.top().0, + cx: bounds.size.width.0, + cy: bounds.size.height.0, } }; unsafe { set_window_long(self.hwnd, GWL_STYLE, style.0 as isize) }; @@ -924,8 +924,8 @@ impl WindowsWindowInner { let height = size_rect.bottom - size_rect.top; self.physical_size.set(Size { - width: DevicePixels(width as i32), - height: DevicePixels(height as i32), + width: DevicePixels(width), + height: DevicePixels(height), }); if self.hide_title_bar { @@ -1076,10 +1076,7 @@ impl WindowsWindowInner { y: lparam.signed_hiword().into(), }; unsafe { ScreenToClient(self.hwnd, &mut cursor_point) }; - let physical_point = point( - DevicePixels(cursor_point.x as i32), - DevicePixels(cursor_point.y as i32), - ); + let physical_point = point(DevicePixels(cursor_point.x), DevicePixels(cursor_point.y)); let click_count = self.click_state.borrow_mut().update(button, physical_point); let scale_factor = self.scale_factor.get(); let event = MouseDownEvent { @@ -1218,10 +1215,10 @@ impl WindowsWindow { .unwrap_or(""), ); let dwstyle = WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX; - let x = options.bounds.origin.x.0 as i32; - let y = options.bounds.origin.y.0 as i32; - let nwidth = options.bounds.size.width.0 as i32; - let nheight = options.bounds.size.height.0 as i32; + let x = options.bounds.origin.x.0; + let y = options.bounds.origin.y.0; + let nwidth = options.bounds.size.width.0; + let nheight = options.bounds.size.height.0; let hwndparent = HWND::default(); let hmenu = HMENU::default(); let hinstance = HINSTANCE::default(); diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs index ecdb46f6038e47..3f51d5024a022a 100644 --- a/crates/project/src/project_tests.rs +++ b/crates/project/src/project_tests.rs @@ -11,7 +11,9 @@ use lsp::Url; use parking_lot::Mutex; use pretty_assertions::assert_eq; use serde_json::json; -use std::{os, task::Poll}; +#[cfg(not(windows))] +use std::os; +use std::task::Poll; use unindent::Unindent as _; use util::{assert_set_eq, paths::PathMatcher, test::temp_tree}; use worktree::WorktreeModelHandle as _; diff --git a/crates/terminal/src/pty_info.rs b/crates/terminal/src/pty_info.rs index 8de4067ca7850a..b01e3661fecedf 100644 --- a/crates/terminal/src/pty_info.rs +++ b/crates/terminal/src/pty_info.rs @@ -60,7 +60,7 @@ impl ProcessIdGetter { } return Some(Pid::from_u32(self.fallback_pid)); } - Some(Pid::from_u32(pid as u32)) + Some(Pid::from_u32(pid)) } } diff --git a/tooling/xtask/src/main.rs b/tooling/xtask/src/main.rs index 9577f9b979a794..103a841fb09226 100644 --- a/tooling/xtask/src/main.rs +++ b/tooling/xtask/src/main.rs @@ -59,9 +59,6 @@ fn run_clippy(args: ClippyArgs) -> Result<()> { clippy_command.arg("--"); // Deny all warnings. - // We don't do this yet on Windows, as it still has some warnings present. - // todo(windows) - #[cfg(not(target_os = "windows"))] clippy_command.args(["--deny", "warnings"]); eprintln!(