From 1b3b82a3c1369c5248a2e6a251230ba6c615e918 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Mon, 30 Aug 2021 19:40:02 +0200 Subject: [PATCH] Clippy fixes (#2011) * windows: bump winapi version * windows: address dark_mode FIXMEs use now available winapi structures * clippy: fix clippy::upper_case_acronyms warnings * clippy: fix needless_arbitrary_self_type warnings * clippy: fix clone_on_copy warnings * clippy: fix unnecessary_mut_passed warnings * clippy: fix identity_op warnings * clippy: fix misc warnings * prefix rustdoc lints with rustdoc:: the prefix was introduced in Rust 1.52 * windows: silence file_drop_handler is never read warning * clippy: fix from_over_into warnings and a bit of naming simplification * clippy: fix missing_safety_doc warnings * make dummy() functions const --- Cargo.toml | 2 +- src/dpi.rs | 90 +++++++++++------------ src/event.rs | 28 ++++--- src/lib.rs | 2 +- src/platform_impl/android/mod.rs | 4 +- src/platform_impl/ios/mod.rs | 2 +- src/platform_impl/ios/window.rs | 2 +- src/platform_impl/linux/mod.rs | 4 +- src/platform_impl/linux/wayland/mod.rs | 4 +- src/platform_impl/linux/x11/mod.rs | 4 +- src/platform_impl/macos/mod.rs | 2 +- src/platform_impl/macos/window.rs | 2 +- src/platform_impl/web/device.rs | 2 +- src/platform_impl/web/window.rs | 2 +- src/platform_impl/windows/dark_mode.rs | 44 +++-------- src/platform_impl/windows/drop_handler.rs | 10 +-- src/platform_impl/windows/event.rs | 8 +- src/platform_impl/windows/event_loop.rs | 24 +++--- src/platform_impl/windows/mod.rs | 4 +- src/platform_impl/windows/util.rs | 2 +- src/platform_impl/windows/window.rs | 8 +- src/window.rs | 12 ++- 22 files changed, 119 insertions(+), 143 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d9aebc4b..d8951b2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,7 +58,7 @@ features = ["display_link"] parking_lot = "0.11" [target.'cfg(target_os = "windows")'.dependencies.winapi] -version = "0.3.6" +version = "0.3.9" features = [ "combaseapi", "commctrl", diff --git a/src/dpi.rs b/src/dpi.rs index 0200a422..be6d8177 100644 --- a/src/dpi.rs +++ b/src/dpi.rs @@ -211,9 +211,9 @@ impl From<(X, X)> for LogicalPosition

{ } } -impl Into<(X, X)> for LogicalPosition

{ - fn into(self: Self) -> (X, X) { - (self.x.cast(), self.y.cast()) +impl From> for (X, X) { + fn from(p: LogicalPosition

) -> (X, X) { + (p.x.cast(), p.y.cast()) } } @@ -223,26 +223,23 @@ impl From<[X; 2]> for LogicalPosition

{ } } -impl Into<[X; 2]> for LogicalPosition

{ - fn into(self: Self) -> [X; 2] { - [self.x.cast(), self.y.cast()] +impl From> for [X; 2] { + fn from(p: LogicalPosition

) -> [X; 2] { + [p.x.cast(), p.y.cast()] } } #[cfg(feature = "mint")] impl From> for LogicalPosition

{ - fn from(mint: mint::Point2

) -> Self { - Self::new(mint.x, mint.y) + fn from(p: mint::Point2

) -> Self { + Self::new(p.x, p.y) } } #[cfg(feature = "mint")] impl From> for mint::Point2

{ - fn from(winit: LogicalPosition

) -> Self { - mint::Point2 { - x: winit.x, - y: winit.y, - } + fn from(p: LogicalPosition

) -> Self { + mint::Point2 { x: p.x, y: p.y } } } @@ -293,9 +290,9 @@ impl From<(X, X)> for PhysicalPosition

{ } } -impl Into<(X, X)> for PhysicalPosition

{ - fn into(self: Self) -> (X, X) { - (self.x.cast(), self.y.cast()) +impl From> for (X, X) { + fn from(p: PhysicalPosition

) -> (X, X) { + (p.x.cast(), p.y.cast()) } } @@ -305,26 +302,23 @@ impl From<[X; 2]> for PhysicalPosition

{ } } -impl Into<[X; 2]> for PhysicalPosition

{ - fn into(self: Self) -> [X; 2] { - [self.x.cast(), self.y.cast()] +impl From> for [X; 2] { + fn from(p: PhysicalPosition

) -> [X; 2] { + [p.x.cast(), p.y.cast()] } } #[cfg(feature = "mint")] impl From> for PhysicalPosition

{ - fn from(mint: mint::Point2

) -> Self { - Self::new(mint.x, mint.y) + fn from(p: mint::Point2

) -> Self { + Self::new(p.x, p.y) } } #[cfg(feature = "mint")] impl From> for mint::Point2

{ - fn from(winit: PhysicalPosition

) -> Self { - mint::Point2 { - x: winit.x, - y: winit.y, - } + fn from(p: PhysicalPosition

) -> Self { + mint::Point2 { x: p.x, y: p.y } } } @@ -375,9 +369,9 @@ impl From<(X, X)> for LogicalSize

{ } } -impl Into<(X, X)> for LogicalSize

{ - fn into(self: LogicalSize

) -> (X, X) { - (self.width.cast(), self.height.cast()) +impl From> for (X, X) { + fn from(s: LogicalSize

) -> (X, X) { + (s.width.cast(), s.height.cast()) } } @@ -387,25 +381,25 @@ impl From<[X; 2]> for LogicalSize

{ } } -impl Into<[X; 2]> for LogicalSize

{ - fn into(self: Self) -> [X; 2] { - [self.width.cast(), self.height.cast()] +impl From> for [X; 2] { + fn from(s: LogicalSize

) -> [X; 2] { + [s.width.cast(), s.height.cast()] } } #[cfg(feature = "mint")] impl From> for LogicalSize

{ - fn from(mint: mint::Vector2

) -> Self { - Self::new(mint.x, mint.y) + fn from(v: mint::Vector2

) -> Self { + Self::new(v.x, v.y) } } #[cfg(feature = "mint")] impl From> for mint::Vector2

{ - fn from(winit: LogicalSize

) -> Self { + fn from(s: LogicalSize

) -> Self { mint::Vector2 { - x: winit.width, - y: winit.height, + x: s.width, + y: s.height, } } } @@ -454,9 +448,9 @@ impl From<(X, X)> for PhysicalSize

{ } } -impl Into<(X, X)> for PhysicalSize

{ - fn into(self: Self) -> (X, X) { - (self.width.cast(), self.height.cast()) +impl From> for (X, X) { + fn from(s: PhysicalSize

) -> (X, X) { + (s.width.cast(), s.height.cast()) } } @@ -466,25 +460,25 @@ impl From<[X; 2]> for PhysicalSize

{ } } -impl Into<[X; 2]> for PhysicalSize

{ - fn into(self: Self) -> [X; 2] { - [self.width.cast(), self.height.cast()] +impl From> for [X; 2] { + fn from(s: PhysicalSize

) -> [X; 2] { + [s.width.cast(), s.height.cast()] } } #[cfg(feature = "mint")] impl From> for PhysicalSize

{ - fn from(mint: mint::Vector2

) -> Self { - Self::new(mint.x, mint.y) + fn from(v: mint::Vector2

) -> Self { + Self::new(v.x, v.y) } } #[cfg(feature = "mint")] impl From> for mint::Vector2

{ - fn from(winit: PhysicalSize

) -> Self { + fn from(s: PhysicalSize

) -> Self { mint::Vector2 { - x: winit.width, - y: winit.height, + x: s.width, + y: s.height, } } } diff --git a/src/event.rs b/src/event.rs index 4de6c36d..6660e006 100644 --- a/src/event.rs +++ b/src/event.rs @@ -131,7 +131,7 @@ impl Clone for Event<'static, T> { device_id: *device_id, event: event.clone(), }, - NewEvents(cause) => NewEvents(cause.clone()), + NewEvents(cause) => NewEvents(*cause), MainEventsCleared => MainEventsCleared, RedrawRequested(wid) => RedrawRequested(*wid), RedrawEventsCleared => RedrawEventsCleared, @@ -358,8 +358,8 @@ impl Clone for WindowEvent<'static> { fn clone(&self) -> Self { use self::WindowEvent::*; return match self { - Resized(size) => Resized(size.clone()), - Moved(pos) => Moved(pos.clone()), + Resized(size) => Resized(*size), + Moved(pos) => Moved(*pos), CloseRequested => CloseRequested, Destroyed => Destroyed, DroppedFile(file) => DroppedFile(file.clone()), @@ -377,7 +377,7 @@ impl Clone for WindowEvent<'static> { is_synthetic: *is_synthetic, }, - ModifiersChanged(modifiers) => ModifiersChanged(modifiers.clone()), + ModifiersChanged(modifiers) => ModifiersChanged(*modifiers), #[allow(deprecated)] CursorMoved { device_id, @@ -437,7 +437,7 @@ impl Clone for WindowEvent<'static> { value: *value, }, Touch(touch) => Touch(*touch), - ThemeChanged(theme) => ThemeChanged(theme.clone()), + ThemeChanged(theme) => ThemeChanged(*theme), ScaleFactorChanged { .. } => { unreachable!("Static event can't be about scale factor changing") } @@ -538,12 +538,16 @@ impl<'a> WindowEvent<'a> { pub struct DeviceId(pub(crate) platform_impl::DeviceId); impl DeviceId { - /// Returns a dummy `DeviceId`, useful for unit testing. The only guarantee made about the return - /// value of this function is that it will always be equal to itself and to future values returned - /// by this function. No other guarantees are made. This may be equal to a real `DeviceId`. + /// Returns a dummy `DeviceId`, useful for unit testing. + /// + /// # Safety + /// + /// The only guarantee made about the return value of this function is that + /// it will always be equal to itself and to future values returned by this function. + /// No other guarantees are made. This may be equal to a real `DeviceId`. /// /// **Passing this into a winit function will result in undefined behavior.** - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { DeviceId(platform_impl::DeviceId::dummy()) } } @@ -998,9 +1002,9 @@ bitflags! { // left and right modifiers are currently commented out, but we should be able to support // them in a future release /// The "shift" key. - const SHIFT = 0b100 << 0; - // const LSHIFT = 0b010 << 0; - // const RSHIFT = 0b001 << 0; + const SHIFT = 0b100; + // const LSHIFT = 0b010; + // const RSHIFT = 0b001; /// The "control" key. const CTRL = 0b100 << 3; // const LCTRL = 0b010 << 3; diff --git a/src/lib.rs b/src/lib.rs index c3101d8d..9b549302 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,7 +130,7 @@ //! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle #![deny(rust_2018_idioms)] -#![deny(broken_intra_doc_links)] +#![deny(rustdoc::broken_intra_doc_links)] #[allow(unused_imports)] #[macro_use] diff --git a/src/platform_impl/android/mod.rs b/src/platform_impl/android/mod.rs index b7853cf0..725e41c4 100644 --- a/src/platform_impl/android/mod.rs +++ b/src/platform_impl/android/mod.rs @@ -443,7 +443,7 @@ impl EventLoopWindowTarget { pub struct WindowId; impl WindowId { - pub fn dummy() -> Self { + pub const fn dummy() -> Self { WindowId } } @@ -452,7 +452,7 @@ impl WindowId { pub struct DeviceId; impl DeviceId { - pub fn dummy() -> Self { + pub const fn dummy() -> Self { DeviceId } } diff --git a/src/platform_impl/ios/mod.rs b/src/platform_impl/ios/mod.rs index da7b0185..4ff1d398 100644 --- a/src/platform_impl/ios/mod.rs +++ b/src/platform_impl/ios/mod.rs @@ -91,7 +91,7 @@ pub struct DeviceId { } impl DeviceId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { DeviceId { uiscreen: std::ptr::null_mut(), } diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index b6d32ffd..036bdf20 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -611,7 +611,7 @@ pub struct WindowId { } impl WindowId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { WindowId { window: std::ptr::null_mut(), } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index 15c14582..dfcc489f 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -141,7 +141,7 @@ pub enum WindowId { } impl WindowId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { #[cfg(feature = "wayland")] return WindowId::Wayland(wayland::WindowId::dummy()); #[cfg(all(not(feature = "wayland"), feature = "x11"))] @@ -158,7 +158,7 @@ pub enum DeviceId { } impl DeviceId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { #[cfg(feature = "wayland")] return DeviceId::Wayland(wayland::DeviceId::dummy()); #[cfg(all(not(feature = "wayland"), feature = "x11"))] diff --git a/src/platform_impl/linux/wayland/mod.rs b/src/platform_impl/linux/wayland/mod.rs index a63a6f1e..4ed564ae 100644 --- a/src/platform_impl/linux/wayland/mod.rs +++ b/src/platform_impl/linux/wayland/mod.rs @@ -22,7 +22,7 @@ mod window; pub struct DeviceId; impl DeviceId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { DeviceId } } @@ -31,7 +31,7 @@ impl DeviceId { pub struct WindowId(usize); impl WindowId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { WindowId(0) } } diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 7f462ab6..c453ed56 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -490,7 +490,7 @@ impl<'a> Deref for DeviceInfo<'a> { pub struct WindowId(ffi::Window); impl WindowId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { WindowId(0) } } @@ -499,7 +499,7 @@ impl WindowId { pub struct DeviceId(c_int); impl DeviceId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { DeviceId(0) } } diff --git a/src/platform_impl/macos/mod.rs b/src/platform_impl/macos/mod.rs index a7c29027..72daf36c 100644 --- a/src/platform_impl/macos/mod.rs +++ b/src/platform_impl/macos/mod.rs @@ -33,7 +33,7 @@ pub(crate) use crate::icon::NoIcon as PlatformIcon; pub struct DeviceId; impl DeviceId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { DeviceId } } diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index 68ef526d..7b46ba9a 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -51,7 +51,7 @@ use objc::{ pub struct Id(pub usize); impl Id { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { Id(0) } } diff --git a/src/platform_impl/web/device.rs b/src/platform_impl/web/device.rs index a2f00b69..a54d0fb2 100644 --- a/src/platform_impl/web/device.rs +++ b/src/platform_impl/web/device.rs @@ -2,7 +2,7 @@ pub struct Id(pub i32); impl Id { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { Id(0) } } diff --git a/src/platform_impl/web/window.rs b/src/platform_impl/web/window.rs index 9e1b8425..7d3942f5 100644 --- a/src/platform_impl/web/window.rs +++ b/src/platform_impl/web/window.rs @@ -344,7 +344,7 @@ impl Drop for Window { pub struct Id(pub(crate) u32); impl Id { - pub unsafe fn dummy() -> Id { + pub const unsafe fn dummy() -> Id { Id(0) } } diff --git a/src/platform_impl/windows/dark_mode.rs b/src/platform_impl/windows/dark_mode.rs index 6aabbf8b..b010d29b 100644 --- a/src/platform_impl/windows/dark_mode.rs +++ b/src/platform_impl/windows/dark_mode.rs @@ -6,38 +6,24 @@ use std::os::windows::ffi::OsStrExt; use winapi::{ shared::{ basetsd::SIZE_T, - minwindef::{BOOL, DWORD, FALSE, UINT, ULONG, WORD}, - ntdef::{LPSTR, NTSTATUS, NT_SUCCESS, PVOID, WCHAR}, + minwindef::{BOOL, DWORD, FALSE, WORD}, + ntdef::{NTSTATUS, NT_SUCCESS, PVOID}, windef::HWND, winerror::S_OK, }, - um::{libloaderapi, uxtheme, winuser}, + um::{libloaderapi, uxtheme, winnt, winuser}, }; use crate::window::Theme; lazy_static! { static ref WIN10_BUILD_VERSION: Option = { - // FIXME: RtlGetVersion is a documented windows API, - // should be part of winapi! - - #[allow(non_snake_case)] - #[repr(C)] - struct OSVERSIONINFOW { - dwOSVersionInfoSize: ULONG, - dwMajorVersion: ULONG, - dwMinorVersion: ULONG, - dwBuildNumber: ULONG, - dwPlatformId: ULONG, - szCSDVersion: [WCHAR; 128], - } - - type RtlGetVersion = unsafe extern "system" fn (*mut OSVERSIONINFOW) -> NTSTATUS; + type RtlGetVersion = unsafe extern "system" fn (*mut winnt::OSVERSIONINFOW) -> NTSTATUS; let handle = get_function!("ntdll.dll", RtlGetVersion); if let Some(rtl_get_version) = handle { unsafe { - let mut vi = OSVERSIONINFOW { + let mut vi = winnt::OSVERSIONINFOW { dwOSVersionInfoSize: 0, dwMajorVersion: 0, dwMinorVersion: 0, @@ -108,11 +94,12 @@ fn set_dark_mode_for_window(hwnd: HWND, is_dark_mode: bool) -> bool { type SetWindowCompositionAttribute = unsafe extern "system" fn(HWND, *mut WINDOWCOMPOSITIONATTRIBDATA) -> BOOL; - #[allow(non_snake_case)] + #[allow(clippy::upper_case_acronyms)] type WINDOWCOMPOSITIONATTRIB = u32; const WCA_USEDARKMODECOLORS: WINDOWCOMPOSITIONATTRIB = 26; #[allow(non_snake_case)] + #[allow(clippy::upper_case_acronyms)] #[repr(C)] struct WINDOWCOMPOSITIONATTRIBDATA { Attrib: WINDOWCOMPOSITIONATTRIB, @@ -181,21 +168,8 @@ fn should_apps_use_dark_mode() -> bool { .unwrap_or(false) } -// FIXME: This definition was missing from winapi. Can remove from -// here and use winapi once the following PR is released: -// https://github.com/retep998/winapi-rs/pull/815 -#[repr(C)] -#[allow(non_snake_case)] -struct HIGHCONTRASTA { - cbSize: UINT, - dwFlags: DWORD, - lpszDefaultScheme: LPSTR, -} - -const HCF_HIGHCONTRASTON: DWORD = 1; - fn is_high_contrast() -> bool { - let mut hc = HIGHCONTRASTA { + let mut hc = winuser::HIGHCONTRASTA { cbSize: 0, dwFlags: 0, lpszDefaultScheme: std::ptr::null_mut(), @@ -210,7 +184,7 @@ fn is_high_contrast() -> bool { ) }; - ok != FALSE && (HCF_HIGHCONTRASTON & hc.dwFlags) == 1 + ok != FALSE && (winuser::HCF_HIGHCONTRASTON & hc.dwFlags) == 1 } fn widestring(src: &'static str) -> Vec { diff --git a/src/platform_impl/windows/drop_handler.rs b/src/platform_impl/windows/drop_handler.rs index f6c7a044..3514d577 100644 --- a/src/platform_impl/windows/drop_handler.rs +++ b/src/platform_impl/windows/drop_handler.rs @@ -181,7 +181,7 @@ impl FileDropHandler { }, }; - let mut drop_format = FORMATETC { + let drop_format = FORMATETC { cfFormat: CF_HDROP as CLIPFORMAT, ptd: ptr::null(), dwAspect: DVASPECT_CONTENT, @@ -190,7 +190,7 @@ impl FileDropHandler { }; let mut medium = std::mem::zeroed(); - let get_data_result = (*data_obj).GetData(&mut drop_format, &mut medium); + let get_data_result = (*data_obj).GetData(&drop_format, &mut medium); if SUCCEEDED(get_data_result) { let hglobal = (*medium.u).hGlobal(); let hdrop = (*hglobal) as shellapi::HDROP; @@ -213,15 +213,15 @@ impl FileDropHandler { callback(OsString::from_wide(&path_buf[0..character_count]).into()); } - return Some(hdrop); + Some(hdrop) } else if get_data_result == DV_E_FORMATETC { // If the dropped item is not a file this error will occur. // In this case it is OK to return without taking further action. debug!("Error occured while processing dropped/hovered item: item is not a file."); - return None; + None } else { debug!("Unexpected error occured while processing dropped/hovered item."); - return None; + None } } } diff --git a/src/platform_impl/windows/event.rs b/src/platform_impl/windows/event.rs index 161cf6b2..77bd31d2 100644 --- a/src/platform_impl/windows/event.rs +++ b/src/platform_impl/windows/event.rs @@ -39,8 +39,8 @@ pub fn get_key_mods() -> ModifiersState { bitflags! { #[derive(Default)] pub struct ModifiersStateSide: u32 { - const LSHIFT = 0b010 << 0; - const RSHIFT = 0b001 << 0; + const LSHIFT = 0b010; + const RSHIFT = 0b001; const LCTRL = 0b010 << 3; const RCTRL = 0b001 << 3; @@ -343,7 +343,7 @@ pub fn handle_extended_keys( extended: bool, ) -> Option<(c_int, UINT)> { // Welcome to hell https://blog.molecular-matters.com/2011/09/05/properly-handling-keyboard-input/ - scancode = if extended { 0xE000 } else { 0x0000 } | scancode; + scancode |= if extended { 0xE000 } else { 0x0000 }; let vkey = match vkey { winuser::VK_SHIFT => unsafe { winuser::MapVirtualKeyA(scancode, winuser::MAPVK_VSC_TO_VK_EX) as _ @@ -369,7 +369,7 @@ pub fn handle_extended_keys( // Don't emit anything for the LeftControl event in the pair... 0xE01D if vkey == winuser::VK_PAUSE => return None, // ...and emit the Pause event for the second event in the pair. - 0x45 if vkey == winuser::VK_PAUSE || vkey == 0xFF as _ => { + 0x45 if vkey == winuser::VK_PAUSE || vkey == 0xFF => { scancode = 0xE059; winuser::VK_PAUSE } diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 17d7def6..8c9fc63b 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -86,7 +86,7 @@ lazy_static! { pub(crate) struct WindowData { pub window_state: Arc>, pub event_loop_runner: EventLoopRunnerShared, - pub file_drop_handler: Option, + pub _file_drop_handler: Option, pub userdata_removed: Cell, pub recurse_depth: Cell, } @@ -217,8 +217,8 @@ impl EventLoop { if 0 == winuser::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) { break 'main; } - winuser::TranslateMessage(&mut msg); - winuser::DispatchMessageW(&mut msg); + winuser::TranslateMessage(&msg); + winuser::DispatchMessageW(&msg); if let Err(payload) = runner.take_panic_error() { runner.reset_runner(); @@ -345,15 +345,15 @@ fn wait_thread(parent_thread_id: DWORD, msg_window_id: HWND) { if wait_until_opt.is_some() { if 0 != winuser::PeekMessageW(&mut msg, ptr::null_mut(), 0, 0, winuser::PM_REMOVE) { - winuser::TranslateMessage(&mut msg); - winuser::DispatchMessageW(&mut msg); + winuser::TranslateMessage(&msg); + winuser::DispatchMessageW(&msg); } } else { if 0 == winuser::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) { break 'main; } else { - winuser::TranslateMessage(&mut msg); - winuser::DispatchMessageW(&mut msg); + winuser::TranslateMessage(&msg); + winuser::DispatchMessageW(&msg); } } @@ -714,8 +714,8 @@ unsafe fn flush_paint_messages( return; } - winuser::TranslateMessage(&mut msg); - winuser::DispatchMessageW(&mut msg); + winuser::TranslateMessage(&msg); + winuser::DispatchMessageW(&msg); }); true } else { @@ -938,7 +938,7 @@ unsafe fn public_window_callback_inner( winuser::MonitorFromRect(&new_rect, winuser::MONITOR_DEFAULTTONULL); match fullscreen { Fullscreen::Borderless(ref mut fullscreen_monitor) => { - if new_monitor != ptr::null_mut() + if !new_monitor.is_null() && fullscreen_monitor .as_ref() .map(|monitor| new_monitor != monitor.inner.hmonitor()) @@ -1020,8 +1020,8 @@ unsafe fn public_window_callback_inner( winuser::WM_CHAR | winuser::WM_SYSCHAR => { use crate::event::WindowEvent::ReceivedCharacter; use std::char; - let is_high_surrogate = 0xD800 <= wparam && wparam <= 0xDBFF; - let is_low_surrogate = 0xDC00 <= wparam && wparam <= 0xDFFF; + let is_high_surrogate = (0xD800..=0xDBFF).contains(&wparam); + let is_low_surrogate = (0xDC00..=0xDFFF).contains(&wparam); if is_high_surrogate { userdata.window_state.lock().high_surrogate = Some(wparam as u16); diff --git a/src/platform_impl/windows/mod.rs b/src/platform_impl/windows/mod.rs index 07629e6d..9215a923 100644 --- a/src/platform_impl/windows/mod.rs +++ b/src/platform_impl/windows/mod.rs @@ -58,7 +58,7 @@ unsafe impl Sync for Cursor {} pub struct DeviceId(u32); impl DeviceId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { DeviceId(0) } } @@ -88,7 +88,7 @@ unsafe impl Send for WindowId {} unsafe impl Sync for WindowId {} impl WindowId { - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { use std::ptr::null_mut; WindowId(null_mut()) diff --git a/src/platform_impl/windows/util.rs b/src/platform_impl/windows/util.rs index 5faaae3e..4ca6cf91 100644 --- a/src/platform_impl/windows/util.rs +++ b/src/platform_impl/windows/util.rs @@ -30,7 +30,7 @@ where } pub fn wchar_to_string(wchar: &[wchar_t]) -> String { - String::from_utf16_lossy(wchar).to_string() + String::from_utf16_lossy(wchar) } pub fn wchar_ptr_to_string(wchar: *const wchar_t) -> String { diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index c8a00f50..7e002e16 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -116,7 +116,7 @@ impl Window { event_loop::WindowData { window_state: win.window_state.clone(), event_loop_runner: event_loop.runner_shared.clone(), - file_drop_handler, + _file_drop_handler: file_drop_handler, userdata_removed: Cell::new(false), recurse_depth: Cell::new(0), } @@ -455,7 +455,7 @@ impl Window { // string, so add it display_name.push(0); - let mut native_video_mode = video_mode.video_mode.native_video_mode.clone(); + let mut native_video_mode = video_mode.video_mode.native_video_mode; let res = unsafe { winuser::ChangeDisplaySettingsExW( @@ -896,7 +896,7 @@ unsafe fn post_init( win.set_maximized(true); } - if let Some(_) = attributes.fullscreen { + if attributes.fullscreen.is_some() { win.set_fullscreen(attributes.fullscreen); force_window_active(win.window.0); } @@ -986,7 +986,7 @@ unsafe fn taskbar_mark_fullscreen(handle: HWND, fullscreen: bool) { TASKBAR_LIST.with(|task_bar_list_ptr| { let mut task_bar_list = task_bar_list_ptr.get(); - if task_bar_list == ptr::null_mut() { + if task_bar_list.is_null() { use winapi::{shared::winerror::S_OK, Interface}; let hr = combaseapi::CoCreateInstance( diff --git a/src/window.rs b/src/window.rs index 3edfab63..59c8c59f 100644 --- a/src/window.rs +++ b/src/window.rs @@ -69,12 +69,16 @@ impl Drop for Window { pub struct WindowId(pub(crate) platform_impl::WindowId); impl WindowId { - /// Returns a dummy `WindowId`, useful for unit testing. The only guarantee made about the return - /// value of this function is that it will always be equal to itself and to future values returned - /// by this function. No other guarantees are made. This may be equal to a real `WindowId`. + /// Returns a dummy `WindowId`, useful for unit testing. + /// + /// # Safety + /// + /// The only guarantee made about the return value of this function is that + /// it will always be equal to itself and to future values returned by this function. + /// No other guarantees are made. This may be equal to a real `WindowId`. /// /// **Passing this into a winit function will result in undefined behavior.** - pub unsafe fn dummy() -> Self { + pub const unsafe fn dummy() -> Self { WindowId(platform_impl::WindowId::dummy()) } }