fix unnecessary cast lint (#2596)

* fix clippy lints on Windows

* fix lints on other platforms

* a couple more

* again

* don't know what's goging on anymore

* fix examples

* comon

* how about now?

* this is getting annoying

* hmmm

* explicitly set a type

* 😢

* don't cast on x64 targets

* apply code review requests

* fix attributes on expressions

* fix ios
This commit is contained in:
Amr Bashir 2022-12-22 21:35:33 +02:00 committed by GitHub
parent da7422c6e1
commit 402cbd55f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 63 additions and 64 deletions

View file

@ -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);
}
_ => (),
}

View file

@ -519,18 +519,8 @@ impl Size {
max.into().to_physical::<f64>(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()
}

View file

@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_cast)]
use std::{
collections::{BTreeSet, VecDeque},
fmt,

View file

@ -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];

View file

@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_cast)]
use std::{
collections::VecDeque,
ops::{Deref, DerefMut},

View file

@ -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]

View file

@ -57,7 +57,7 @@ impl<T: 'static> EventProcessor<T> {
F: Fn(&Arc<UnownedWindow>) -> 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<T: 'static> EventProcessor<T> {
// 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<T: 'static> EventProcessor<T> {
// 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<T: 'static> EventProcessor<T> {
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.

View file

@ -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)))

View file

@ -108,6 +108,7 @@ impl std::hash::Hash for MonitorHandle {
#[inline]
pub fn mode_refresh_rate_millihertz(mode: &XRRModeInfo) -> Option<u32> {
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<Self> {
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<u32> {

View file

@ -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 _,
),
)
}

View file

@ -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)> {

View file

@ -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 _),
)
}
}

View file

@ -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();
}

View file

@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_cast)]
use std::collections::VecDeque;
use objc2::foundation::NSObject;

View file

@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_cast)]
use std::{collections::VecDeque, fmt};
use core_foundation::{

View file

@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_cast)]
mod r#async;
pub(crate) use self::r#async::*;

View file

@ -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};

View file

@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_cast)]
use std::{
collections::VecDeque,
f64, ops,

View file

@ -1,3 +1,5 @@
#![allow(clippy::unnecessary_cast)]
use std::ptr;
use objc2::declare::{Ivar, IvarDrop};

View file

@ -322,8 +322,8 @@ impl<T: 'static> Shared<T> {
};
// 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::<f64>(old_scale);
let mut new_size = logical_size.to_physical(new_scale);

View file

@ -238,16 +238,16 @@ impl<T> EventLoopWindowTarget<T> {
// 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())

View file

@ -65,7 +65,7 @@ pub fn get_monitor_dpi(hmonitor: HMONITOR) -> Option<u32> {
// 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
}

View file

@ -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,
};

View file

@ -1151,8 +1151,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
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<T: 'static>(
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
}

View file

@ -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,
)
};

View file

@ -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),
},

View file

@ -140,7 +140,7 @@ impl Window {
#[inline]
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, 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]