diff --git a/examples/child_window.rs b/examples/child_window.rs index ce240c8e..865e72f5 100644 --- a/examples/child_window.rs +++ b/examples/child_window.rs @@ -25,7 +25,7 @@ fn main() { .with_inner_size(LogicalSize::new(200.0f32, 200.0f32)) .with_position(Position::Logical(LogicalPosition::new(0.0, 0.0))) .with_visible(true); - // `with_parent_window` is unsafe. Parent window must a valid window. + // `with_parent_window` is unsafe. Parent window must be a valid window. builder = unsafe { builder.with_parent_window(Some(parent)) }; let child_window = builder.build(event_loop).unwrap(); @@ -44,8 +44,7 @@ fn main() { .build(&event_loop) .unwrap(); - let root = parent_window; - println!("parent window: {:?})", root); + println!("parent window: {:?})", parent_window); event_loop.run(move |event: Event<'_, ()>, event_loop, control_flow| { *control_flow = ControlFlow::Wait; @@ -71,7 +70,7 @@ fn main() { }, .. } => { - spawn_child_window(&root, event_loop, &mut windows); + spawn_child_window(&parent_window, event_loop, &mut windows); } _ => (), } diff --git a/src/dpi.rs b/src/dpi.rs index 7d372d88..c35d3ade 100644 --- a/src/dpi.rs +++ b/src/dpi.rs @@ -519,18 +519,8 @@ impl Size { max.into().to_physical::(scale_factor), ); - let clamp = |input: f64, min: f64, max: f64| { - if input < min { - min - } else if input > max { - max - } else { - input - } - }; - - let width = clamp(input.width, min.width, max.width); - let height = clamp(input.height, min.height, max.height); + let width = input.width.clamp(min.width, max.width); + let height = input.height.clamp(min.height, max.height); PhysicalSize::new(width, height).into() } diff --git a/src/platform_impl/ios/monitor.rs b/src/platform_impl/ios/monitor.rs index f6402921..7f7e037b 100644 --- a/src/platform_impl/ios/monitor.rs +++ b/src/platform_impl/ios/monitor.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use std::{ collections::{BTreeSet, VecDeque}, fmt, diff --git a/src/platform_impl/ios/view.rs b/src/platform_impl/ios/view.rs index 466b8eec..bc27360f 100644 --- a/src/platform_impl/ios/view.rs +++ b/src/platform_impl/ios/view.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use objc2::foundation::NSObject; use objc2::{class, declare_class, msg_send, ClassType}; @@ -105,7 +107,6 @@ declare_class!( && scale_factor > 0.0, "invalid scale_factor set on UIView", ); - let scale_factor = scale_factor as f64; let bounds: CGRect = msg_send![self, bounds]; let screen: id = msg_send![window, screen]; let screen_space: id = msg_send![screen, coordinateSpace]; diff --git a/src/platform_impl/ios/window.rs b/src/platform_impl/ios/window.rs index e3f33908..12c0cbfd 100644 --- a/src/platform_impl/ios/window.rs +++ b/src/platform_impl/ios/window.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use std::{ collections::VecDeque, ops::{Deref, DerefMut}, diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index aa92d557..4677b8cd 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -257,7 +257,7 @@ impl MonitorHandle { #[inline] pub fn scale_factor(&self) -> f64 { - x11_or_wayland!(match self; MonitorHandle(m) => m.scale_factor() as f64) + x11_or_wayland!(match self; MonitorHandle(m) => m.scale_factor() as _) } #[inline] @@ -437,7 +437,7 @@ impl Window { #[inline] pub fn scale_factor(&self) -> f64 { - x11_or_wayland!(match self; Window(w) => w.scale_factor() as f64) + x11_or_wayland!(match self; Window(w) => w.scale_factor() as _) } #[inline] diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 18bcf902..11c9a6a9 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -57,7 +57,7 @@ impl EventProcessor { F: Fn(&Arc) -> Ret, { let mut deleted = false; - let window_id = WindowId(window_id as u64); + let window_id = WindowId(window_id as _); let wt = get_xtarget(&self.target); let result = wt .windows @@ -347,7 +347,7 @@ impl EventProcessor { // These are both in physical space. let new_inner_size = (xev.width as u32, xev.height as u32); - let new_inner_position = (xev.x as i32, xev.y as i32); + let new_inner_position = (xev.x, xev.y); let (mut resized, moved) = { let mut shared_state_lock = window.shared_state_lock(); @@ -520,7 +520,7 @@ impl EventProcessor { // In the event that the window's been destroyed without being dropped first, we // cleanup again here. - wt.windows.borrow_mut().remove(&WindowId(window as u64)); + wt.windows.borrow_mut().remove(&WindowId(window as _)); // Since all XIM stuff needs to happen from the same thread, we destroy the input // context here instead of when dropping the window. @@ -1021,8 +1021,7 @@ impl EventProcessor { if self.window_exists(xev.event) { let id = xev.detail as u64; let modifiers = self.device_mod_state.modifiers(); - let location = - PhysicalPosition::new(xev.event_x as f64, xev.event_y as f64); + let location = PhysicalPosition::new(xev.event_x, xev.event_y); // Mouse cursor position changes when touch events are received. // Only the first concurrently active touch ID moves the mouse cursor. diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 8d5ef389..92384b6f 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -711,7 +711,7 @@ struct XExtension { } fn mkwid(w: ffi::Window) -> crate::window::WindowId { - crate::window::WindowId(crate::platform_impl::platform::WindowId(w as u64)) + crate::window::WindowId(crate::platform_impl::platform::WindowId(w as _)) } fn mkdid(w: c_int) -> crate::event::DeviceId { crate::event::DeviceId(crate::platform_impl::DeviceId::X(DeviceId(w))) diff --git a/src/platform_impl/linux/x11/monitor.rs b/src/platform_impl/linux/x11/monitor.rs index 8f686081..297e3deb 100644 --- a/src/platform_impl/linux/x11/monitor.rs +++ b/src/platform_impl/linux/x11/monitor.rs @@ -108,6 +108,7 @@ impl std::hash::Hash for MonitorHandle { #[inline] pub fn mode_refresh_rate_millihertz(mode: &XRRModeInfo) -> Option { if mode.dotClock > 0 && mode.hTotal > 0 && mode.vTotal > 0 { + #[allow(clippy::unnecessary_cast)] Some((mode.dotClock as u64 * 1000 / (mode.hTotal as u64 * mode.vTotal as u64)) as u32) } else { None @@ -123,8 +124,8 @@ impl MonitorHandle { primary: bool, ) -> Option { let (name, scale_factor, video_modes) = unsafe { xconn.get_output_info(resources, crtc)? }; - let dimensions = unsafe { ((*crtc).width as u32, (*crtc).height as u32) }; - let position = unsafe { ((*crtc).x as i32, (*crtc).y as i32) }; + let dimensions = unsafe { ((*crtc).width, (*crtc).height) }; + let position = unsafe { ((*crtc).x, (*crtc).y) }; // Get the refresh rate of the current video mode. let current_mode = unsafe { (*crtc).mode }; @@ -175,7 +176,7 @@ impl MonitorHandle { #[inline] pub fn native_identifier(&self) -> u32 { - self.id as u32 + self.id as _ } pub fn size(&self) -> PhysicalSize { diff --git a/src/platform_impl/linux/x11/util/geometry.rs b/src/platform_impl/linux/x11/util/geometry.rs index 8a0c8a5b..7afced80 100644 --- a/src/platform_impl/linux/x11/util/geometry.rs +++ b/src/platform_impl/linux/x11/util/geometry.rs @@ -129,12 +129,12 @@ impl FrameExtentsHeuristic { width.saturating_add( self.frame_extents .left - .saturating_add(self.frame_extents.right) as u32, + .saturating_add(self.frame_extents.right) as _, ), height.saturating_add( self.frame_extents .top - .saturating_add(self.frame_extents.bottom) as u32, + .saturating_add(self.frame_extents.bottom) as _, ), ) } diff --git a/src/platform_impl/linux/x11/util/hint.rs b/src/platform_impl/linux/x11/util/hint.rs index 723dfad4..51d56a16 100644 --- a/src/platform_impl/linux/x11/util/hint.rs +++ b/src/platform_impl/linux/x11/util/hint.rs @@ -198,7 +198,7 @@ impl<'a> NormalHints<'a> { pub fn get_position(&self) -> Option<(i32, i32)> { has_flag(self.size_hints.flags, ffi::PPosition) - .then(|| (self.size_hints.x as i32, self.size_hints.y as i32)) + .then(|| (self.size_hints.x, self.size_hints.y)) } pub fn get_resize_increments(&self) -> Option<(u32, u32)> { diff --git a/src/platform_impl/linux/x11/util/randr.rs b/src/platform_impl/linux/x11/util/randr.rs index c3489dc3..24f9f631 100644 --- a/src/platform_impl/linux/x11/util/randr.rs +++ b/src/platform_impl/linux/x11/util/randr.rs @@ -126,11 +126,8 @@ impl XConnection { let scale_factor = match dpi_env { EnvVarDPI::Randr => calc_dpi_factor( - ((*crtc).width as u32, (*crtc).height as u32), - ( - (*output_info).mm_width as u64, - (*output_info).mm_height as u64, - ), + ((*crtc).width, (*crtc).height), + ((*output_info).mm_width as _, (*output_info).mm_height as _), ), EnvVarDPI::Scale(dpi_override) => { if !validate_scale_factor(dpi_override) { @@ -146,11 +143,8 @@ impl XConnection { dpi / 96. } else { calc_dpi_factor( - ((*crtc).width as u32, (*crtc).height as u32), - ( - (*output_info).mm_width as u64, - (*output_info).mm_height as u64, - ), + ((*crtc).width, (*crtc).height), + ((*output_info).mm_width as _, (*output_info).mm_height as _), ) } } diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 2b4ee08c..981d56cf 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -1551,14 +1551,14 @@ impl UnownedWindow { #[inline] pub fn id(&self) -> WindowId { - WindowId(self.xwindow as u64) + WindowId(self.xwindow as _) } #[inline] pub fn request_redraw(&self) { self.redraw_sender .sender - .send(WindowId(self.xwindow as u64)) + .send(WindowId(self.xwindow as _)) .unwrap(); self.redraw_sender.waker.wake().unwrap(); } diff --git a/src/platform_impl/macos/app.rs b/src/platform_impl/macos/app.rs index 621c8742..4ca5de4e 100644 --- a/src/platform_impl/macos/app.rs +++ b/src/platform_impl/macos/app.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use std::collections::VecDeque; use objc2::foundation::NSObject; diff --git a/src/platform_impl/macos/monitor.rs b/src/platform_impl/macos/monitor.rs index f923881e..07ddfcaa 100644 --- a/src/platform_impl/macos/monitor.rs +++ b/src/platform_impl/macos/monitor.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use std::{collections::VecDeque, fmt}; use core_foundation::{ diff --git a/src/platform_impl/macos/util/mod.rs b/src/platform_impl/macos/util/mod.rs index 98713ac7..2cfdc47e 100644 --- a/src/platform_impl/macos/util/mod.rs +++ b/src/platform_impl/macos/util/mod.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + mod r#async; pub(crate) use self::r#async::*; diff --git a/src/platform_impl/macos/view.rs b/src/platform_impl/macos/view.rs index b6e9c69a..bc36ca44 100644 --- a/src/platform_impl/macos/view.rs +++ b/src/platform_impl/macos/view.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use std::{boxed::Box, collections::VecDeque, os::raw::*, ptr, str, sync::Mutex}; use objc2::declare::{Ivar, IvarDrop}; diff --git a/src/platform_impl/macos/window.rs b/src/platform_impl/macos/window.rs index cf284c93..57216eb8 100644 --- a/src/platform_impl/macos/window.rs +++ b/src/platform_impl/macos/window.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use std::{ collections::VecDeque, f64, ops, diff --git a/src/platform_impl/macos/window_delegate.rs b/src/platform_impl/macos/window_delegate.rs index 51f758bb..0d770531 100644 --- a/src/platform_impl/macos/window_delegate.rs +++ b/src/platform_impl/macos/window_delegate.rs @@ -1,3 +1,5 @@ +#![allow(clippy::unnecessary_cast)] + use std::ptr; use objc2::declare::{Ivar, IvarDrop}; diff --git a/src/platform_impl/web/event_loop/runner.rs b/src/platform_impl/web/event_loop/runner.rs index 89634b40..bdb68ff4 100644 --- a/src/platform_impl/web/event_loop/runner.rs +++ b/src/platform_impl/web/event_loop/runner.rs @@ -322,8 +322,8 @@ impl Shared { }; // First, we send the `ScaleFactorChanged` event: let current_size = crate::dpi::PhysicalSize { - width: canvas.width() as u32, - height: canvas.height() as u32, + width: canvas.width(), + height: canvas.height(), }; let logical_size = current_size.to_logical::(old_scale); let mut new_size = logical_size.to_physical(new_scale); diff --git a/src/platform_impl/web/event_loop/window_target.rs b/src/platform_impl/web/event_loop/window_target.rs index 28087d01..77d8e83c 100644 --- a/src/platform_impl/web/event_loop/window_target.rs +++ b/src/platform_impl/web/event_loop/window_target.rs @@ -238,16 +238,16 @@ impl EventLoopWindowTarget { // The size to restore to after exiting fullscreen. let mut intended_size = PhysicalSize { - width: raw.width() as u32, - height: raw.height() as u32, + width: raw.width(), + height: raw.height(), }; canvas.on_fullscreen_change(move || { // If the canvas is marked as fullscreen, it is moving *into* fullscreen // If it is not, it is moving *out of* fullscreen let new_size = if backend::is_fullscreen(&raw) { intended_size = PhysicalSize { - width: raw.width() as u32, - height: raw.height() as u32, + width: raw.width(), + height: raw.height(), }; backend::window_size().to_physical(backend::scale_factor()) diff --git a/src/platform_impl/windows/dpi.rs b/src/platform_impl/windows/dpi.rs index 1a0bf692..e1a5f0ae 100644 --- a/src/platform_impl/windows/dpi.rs +++ b/src/platform_impl/windows/dpi.rs @@ -65,7 +65,7 @@ pub fn get_monitor_dpi(hmonitor: HMONITOR) -> Option { // MSDN says that "the values of *dpiX and *dpiY are identical. You only need to // record one of the values to determine the DPI and respond appropriately". // https://msdn.microsoft.com/en-us/library/windows/desktop/dn280510(v=vs.85).aspx - return Some(dpi_x as u32); + return Some(dpi_x); } } } @@ -86,7 +86,7 @@ pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 { // We are on Windows 10 Anniversary Update (1607) or later. match GetDpiForWindow(hwnd) { 0 => BASE_DPI, // 0 is returned if hwnd is invalid - dpi => dpi as u32, + dpi => dpi, } } else if let Some(GetDpiForMonitor) = *GET_DPI_FOR_MONITOR { // We are on Windows 8.1 or later. @@ -98,7 +98,7 @@ pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 { let mut dpi_x = 0; let mut dpi_y = 0; if GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &mut dpi_x, &mut dpi_y) == S_OK { - dpi_x as u32 + dpi_x } else { BASE_DPI } diff --git a/src/platform_impl/windows/drop_handler.rs b/src/platform_impl/windows/drop_handler.rs index 2db12a67..8ffb87f0 100644 --- a/src/platform_impl/windows/drop_handler.rs +++ b/src/platform_impl/windows/drop_handler.rs @@ -169,7 +169,7 @@ impl FileDropHandler { let drop_format = FORMATETC { cfFormat: CF_HDROP as u16, ptd: ptr::null_mut(), - dwAspect: DVASPECT_CONTENT as u32, + dwAspect: DVASPECT_CONTENT, lindex: -1, tymed: TYMED_HGLOBAL as u32, }; diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 9eb5930c..f954032b 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -1151,8 +1151,7 @@ unsafe fn public_window_callback_inner( let windowpos = lparam as *const WINDOWPOS; if (*windowpos).flags & SWP_NOMOVE != SWP_NOMOVE { - let physical_position = - PhysicalPosition::new((*windowpos).x as i32, (*windowpos).y as i32); + let physical_position = PhysicalPosition::new((*windowpos).x, (*windowpos).y); userdata.send_event(Event::WindowEvent { window_id: RootWindowId(WindowId(window)), event: Moved(physical_position), @@ -2437,7 +2436,7 @@ unsafe extern "system" fn thread_event_target_callback( 0 } _ if msg == *EXEC_MSG_ID => { - let mut function: ThreadExecFn = Box::from_raw(wparam as usize as *mut _); + let mut function: ThreadExecFn = Box::from_raw(wparam as *mut _); function(); 0 } diff --git a/src/platform_impl/windows/icon.rs b/src/platform_impl/windows/icon.rs index a6277da1..0be4fd1f 100644 --- a/src/platform_impl/windows/icon.rs +++ b/src/platform_impl/windows/icon.rs @@ -90,8 +90,8 @@ impl WinIcon { 0, wide_path.as_ptr(), IMAGE_ICON, - width as i32, - height as i32, + width, + height, LR_DEFAULTSIZE | LR_LOADFROMFILE, ) }; @@ -113,8 +113,8 @@ impl WinIcon { util::get_instance_handle(), resource_id as PCWSTR, IMAGE_ICON, - width as i32, - height as i32, + width, + height, LR_DEFAULTSIZE, ) }; diff --git a/src/platform_impl/windows/monitor.rs b/src/platform_impl/windows/monitor.rs index 8e907ad4..7b38fb19 100644 --- a/src/platform_impl/windows/monitor.rs +++ b/src/platform_impl/windows/monitor.rs @@ -241,7 +241,7 @@ impl MonitorHandle { i += 1; const REQUIRED_FIELDS: u32 = - (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY) as u32; + DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; assert!(has_flag(mode.dmFields, REQUIRED_FIELDS)); // Use Ord impl of RootVideoMode @@ -249,7 +249,7 @@ impl MonitorHandle { video_mode: VideoMode { size: (mode.dmPelsWidth, mode.dmPelsHeight), bit_depth: mode.dmBitsPerPel as u16, - refresh_rate_millihertz: mode.dmDisplayFrequency as u32 * 1000, + refresh_rate_millihertz: mode.dmDisplayFrequency * 1000, monitor: self.clone(), native_video_mode: Box::new(mode), }, diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 990b409b..4d6eaacc 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -140,7 +140,7 @@ impl Window { #[inline] pub fn outer_position(&self) -> Result, NotSupportedError> { util::WindowArea::Outer.get_rect(self.hwnd()) - .map(|rect| Ok(PhysicalPosition::new(rect.left as i32, rect.top as i32))) + .map(|rect| Ok(PhysicalPosition::new(rect.left, rect.top))) .expect("Unexpected GetWindowRect failure; please report this error to https://github.com/rust-windowing/winit") } @@ -150,7 +150,7 @@ impl Window { if unsafe { ClientToScreen(self.hwnd(), &mut position) } == false.into() { panic!("Unexpected ClientToScreen failure: please report this error to https://github.com/rust-windowing/winit") } - Ok(PhysicalPosition::new(position.x as i32, position.y as i32)) + Ok(PhysicalPosition::new(position.x, position.y)) } #[inline]