diff --git a/examples/cursor.rs b/examples/cursor.rs index a466e889a8..6ec8a05933 100644 --- a/examples/cursor.rs +++ b/examples/cursor.rs @@ -43,7 +43,6 @@ fn main() { .. } => { *control_flow = ControlFlow::Exit; - return; } _ => (), } diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs index 83fbde30db..90d41ece12 100644 --- a/examples/fullscreen.rs +++ b/examples/fullscreen.rs @@ -15,7 +15,7 @@ fn main() { let mut num = String::new(); stdin().read_line(&mut num).unwrap(); - let num = num.trim().parse().ok().expect("Please enter a number"); + let num = num.trim().parse().expect("Please enter a number"); let fullscreen = Some(match num { 1 => Fullscreen::Exclusive(prompt_for_video_mode(&prompt_for_monitor(&event_loop))), @@ -85,7 +85,7 @@ fn prompt_for_monitor(event_loop: &EventLoop<()>) -> MonitorHandle { let mut num = String::new(); stdin().read_line(&mut num).unwrap(); - let num = num.trim().parse().ok().expect("Please enter a number"); + let num = num.trim().parse().expect("Please enter a number"); let monitor = event_loop .available_monitors() .nth(num) @@ -106,7 +106,7 @@ fn prompt_for_video_mode(monitor: &MonitorHandle) -> VideoMode { let mut num = String::new(); stdin().read_line(&mut num).unwrap(); - let num = num.trim().parse().ok().expect("Please enter a number"); + let num = num.trim().parse().expect("Please enter a number"); let video_mode = monitor .video_modes() .nth(num) diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs index 68cdb60b78..ba2b9ad240 100644 --- a/examples/multithreaded.rs +++ b/examples/multithreaded.rs @@ -34,10 +34,10 @@ fn main() { // We need to update our chosen video mode if the window // was moved to an another monitor, so that the window // appears on this monitor instead when we go fullscreen - let previous_video_mode = video_modes.iter().cloned().nth(video_mode_id); + let previous_video_mode = video_modes.get(video_mode_id).cloned(); video_modes = window.current_monitor().unwrap().video_modes().collect(); video_mode_id = video_mode_id.min(video_modes.len()); - let video_mode = video_modes.iter().nth(video_mode_id); + let video_mode = video_modes.get(video_mode_id); // Different monitors may support different video modes, // and the index we chose previously may now point to a @@ -45,7 +45,7 @@ fn main() { if video_mode != previous_video_mode.as_ref() { println!( "Window moved to another monitor, picked video mode: {}", - video_modes.iter().nth(video_mode_id).unwrap() + video_modes.get(video_mode_id).unwrap() ); } } @@ -77,16 +77,13 @@ fn main() { Right => (video_modes.len() - 1).min(video_mode_id + 1), _ => unreachable!(), }; - println!( - "Picking video mode: {}", - video_modes.iter().nth(video_mode_id).unwrap() - ); + println!("Picking video mode: {}", video_modes[video_mode_id]); } F => window.set_fullscreen(match (state, modifiers.alt()) { (true, false) => Some(Fullscreen::Borderless(None)), - (true, true) => Some(Fullscreen::Exclusive( - video_modes.iter().nth(video_mode_id).unwrap().clone(), - )), + (true, true) => { + Some(Fullscreen::Exclusive(video_modes[video_mode_id].clone())) + } (false, _) => None, }), G => window.set_cursor_grab(state).unwrap(), @@ -173,7 +170,7 @@ fn main() { } } }, - _ => (), + _ => {} } }) } diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs index ec97eee097..e946537296 100644 --- a/examples/multiwindow.rs +++ b/examples/multiwindow.rs @@ -41,7 +41,7 @@ fn main() { }, .. } => { - let window = Window::new(&event_loop).unwrap(); + let window = Window::new(event_loop).unwrap(); windows.insert(window.id(), window); } _ => (), diff --git a/examples/set_ime_position.rs b/examples/set_ime_position.rs index 1b2eecc373..2cd376da0f 100644 --- a/examples/set_ime_position.rs +++ b/examples/set_ime_position.rs @@ -46,7 +46,6 @@ fn main() { .. } => { *control_flow = ControlFlow::Exit; - return; } _ => (), } diff --git a/src/platform_impl/linux/mod.rs b/src/platform_impl/linux/mod.rs index dfcc489fc4..953fca1dd5 100644 --- a/src/platform_impl/linux/mod.rs +++ b/src/platform_impl/linux/mod.rs @@ -118,9 +118,9 @@ impl fmt::Display for OsError { #[cfg(feature = "x11")] OsError::XError(ref e) => _f.pad(&e.description), #[cfg(feature = "x11")] - OsError::XMisc(ref e) => _f.pad(e), + OsError::XMisc(e) => _f.pad(e), #[cfg(feature = "wayland")] - OsError::WaylandMisc(ref e) => _f.pad(e), + OsError::WaylandMisc(e) => _f.pad(e), } } } @@ -409,7 +409,7 @@ impl Window { #[cfg(feature = "x11")] Window::X(ref w) => w.set_always_on_top(_always_on_top), #[cfg(feature = "wayland")] - _ => (), + Window::Wayland(_) => (), } } @@ -419,7 +419,7 @@ impl Window { #[cfg(feature = "x11")] Window::X(ref w) => w.set_window_icon(_window_icon), #[cfg(feature = "wayland")] - _ => (), + Window::Wayland(_) => (), } } @@ -434,7 +434,7 @@ impl Window { #[cfg(feature = "x11")] Window::X(ref w) => w.focus_window(), #[cfg(feature = "wayland")] - _ => (), + Window::Wayland(_) => (), } } pub fn request_user_attention(&self, request_type: Option) { diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 9ae6393564..9e644103d5 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -536,12 +536,12 @@ impl EventLoop { } fn loop_dispatch>>(&mut self, timeout: D) -> IOResult<()> { - let mut state = match &mut self.window_target.p { + let state = match &mut self.window_target.p { PlatformEventLoopWindowTarget::Wayland(window_target) => window_target.state.get_mut(), #[cfg(feature = "x11")] _ => unreachable!(), }; - self.event_loop.dispatch(timeout, &mut state) + self.event_loop.dispatch(timeout, state) } } diff --git a/src/platform_impl/linux/x11/event_processor.rs b/src/platform_impl/linux/x11/event_processor.rs index 2f1d6b77c3..17f9436f58 100644 --- a/src/platform_impl/linux/x11/event_processor.rs +++ b/src/platform_impl/linux/x11/event_processor.rs @@ -45,7 +45,7 @@ impl EventProcessor { let mut devices = self.devices.borrow_mut(); if let Some(info) = DeviceInfo::get(&wt.xconn, device) { for info in info.iter() { - devices.insert(DeviceId(info.deviceid), Device::new(&self, info)); + devices.insert(DeviceId(info.deviceid), Device::new(self, info)); } } } @@ -925,7 +925,7 @@ impl EventProcessor { // Issue key press events for all pressed keys Self::handle_pressed_keys( - &wt, + wt, window_id, ElementState::Pressed, &self.mod_keymap, @@ -949,7 +949,7 @@ impl EventProcessor { // Issue key release events for all pressed keys Self::handle_pressed_keys( - &wt, + wt, window_id, ElementState::Released, &self.mod_keymap, @@ -1220,11 +1220,8 @@ impl EventProcessor { } } - match self.ime_receiver.try_recv() { - Ok((window_id, x, y)) => { - wt.ime.borrow_mut().send_xim_spot(window_id, x, y); - } - Err(_) => (), + if let Ok((window_id, x, y)) = self.ime_receiver.try_recv() { + wt.ime.borrow_mut().send_xim_spot(window_id, x, y); } } diff --git a/src/platform_impl/linux/x11/ime/callbacks.rs b/src/platform_impl/linux/x11/ime/callbacks.rs index f254a04e55..7b599274a4 100644 --- a/src/platform_impl/linux/x11/ime/callbacks.rs +++ b/src/platform_impl/linux/x11/ime/callbacks.rs @@ -62,7 +62,7 @@ pub unsafe fn set_destroy_callback( inner: &ImeInner, ) -> Result<(), XError> { xim_set_callback( - &xconn, + xconn, im, ffi::XNDestroyCallback_0.as_ptr() as *const _, &inner.destroy_callback as *const _ as *mut _, @@ -70,6 +70,7 @@ pub unsafe fn set_destroy_callback( } #[derive(Debug)] +#[allow(clippy::enum_variant_names)] enum ReplaceImError { MethodOpenFailed(PotentialInputMethods), ContextCreationFailed(ImeContextCreationError), @@ -136,13 +137,17 @@ pub unsafe extern "C" fn xim_instantiate_callback( let inner: *mut ImeInner = client_data as _; if !inner.is_null() { let xconn = &(*inner).xconn; - let result = replace_im(inner); - if result.is_ok() { - let _ = unset_instantiate_callback(xconn, client_data); - (*inner).is_fallback = false; - } else if result.is_err() && (*inner).is_destroyed { - // We have no usable input methods! - result.expect("Failed to reopen input method"); + match replace_im(inner) { + Ok(()) => { + let _ = unset_instantiate_callback(xconn, client_data); + (*inner).is_fallback = false; + } + Err(err) => { + if (*inner).is_destroyed { + // We have no usable input methods! + panic!("Failed to reopen input method: {:?}", err); + } + } } } } @@ -163,12 +168,12 @@ pub unsafe extern "C" fn xim_destroy_callback( if !(*inner).is_fallback { let _ = set_instantiate_callback(xconn, client_data); // Attempt to open fallback input method. - let result = replace_im(inner); - if result.is_ok() { - (*inner).is_fallback = true; - } else { - // We have no usable input methods! - result.expect("Failed to open fallback input method"); + match replace_im(inner) { + Ok(()) => (*inner).is_fallback = true, + Err(err) => { + // We have no usable input methods! + panic!("Failed to open fallback input method: {:?}", err); + } } } } diff --git a/src/platform_impl/linux/x11/ime/context.rs b/src/platform_impl/linux/x11/ime/context.rs index 8c2ff4cf50..8d58082052 100644 --- a/src/platform_impl/linux/x11/ime/context.rs +++ b/src/platform_impl/linux/x11/ime/context.rs @@ -58,7 +58,7 @@ impl ImeContext { Ok(ImeContext { ic, - ic_spot: ic_spot.unwrap_or_else(|| ffi::XPoint { x: 0, y: 0 }), + ic_spot: ic_spot.unwrap_or(ffi::XPoint { x: 0, y: 0 }), }) } diff --git a/src/platform_impl/linux/x11/ime/inner.rs b/src/platform_impl/linux/x11/ime/inner.rs index 011e22aa13..97dcf7af6c 100644 --- a/src/platform_impl/linux/x11/ime/inner.rs +++ b/src/platform_impl/linux/x11/ime/inner.rs @@ -58,10 +58,8 @@ impl ImeInner { } pub unsafe fn destroy_all_contexts_if_necessary(&self) -> Result { - for context in self.contexts.values() { - if let &Some(ref context) = context { - self.destroy_ic_if_necessary(context.ic)?; - } + for context in self.contexts.values().flatten() { + self.destroy_ic_if_necessary(context.ic)?; } Ok(!self.is_destroyed) } diff --git a/src/platform_impl/linux/x11/ime/input_method.rs b/src/platform_impl/linux/x11/ime/input_method.rs index 808dfcb7d3..e552f55635 100644 --- a/src/platform_impl/linux/x11/ime/input_method.rs +++ b/src/platform_impl/linux/x11/ime/input_method.rs @@ -63,11 +63,7 @@ pub enum InputMethodResult { impl InputMethodResult { pub fn is_fallback(&self) -> bool { - if let &InputMethodResult::Fallback(_) = self { - true - } else { - false - } + matches!(self, InputMethodResult::Fallback(_)) } pub fn ok(self) -> Option { @@ -249,7 +245,7 @@ impl PotentialInputMethods { pub fn open_im( &mut self, xconn: &Arc, - callback: Option<&dyn Fn() -> ()>, + callback: Option<&dyn Fn()>, ) -> InputMethodResult { use self::InputMethodResult::*; @@ -259,10 +255,8 @@ impl PotentialInputMethods { let im = input_method.open_im(xconn); if let Some(im) = im { return XModifiers(im); - } else { - if let Some(ref callback) = callback { - callback(); - } + } else if let Some(ref callback) = callback { + callback(); } } diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 7adf80e902..27c92c46b3 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -634,25 +634,22 @@ impl Device { // Identify scroll axes for class_ptr in Device::classes(info) { let class = unsafe { &**class_ptr }; - match class._type { - ffi::XIScrollClass => { - let info = unsafe { - mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIScrollClassInfo>(class) - }; - scroll_axes.push(( - info.number, - ScrollAxis { - increment: info.increment, - orientation: match info.scroll_type { - ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal, - ffi::XIScrollTypeVertical => ScrollOrientation::Vertical, - _ => unreachable!(), - }, - position: 0.0, + if class._type == ffi::XIScrollClass { + let info = unsafe { + mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIScrollClassInfo>(class) + }; + scroll_axes.push(( + info.number, + ScrollAxis { + increment: info.increment, + orientation: match info.scroll_type { + ffi::XIScrollTypeHorizontal => ScrollOrientation::Horizontal, + ffi::XIScrollTypeVertical => ScrollOrientation::Vertical, + _ => unreachable!(), }, - )); - } - _ => {} + position: 0.0, + }, + )); } } } @@ -670,20 +667,17 @@ impl Device { if Device::physical_device(info) { for class_ptr in Device::classes(info) { let class = unsafe { &**class_ptr }; - match class._type { - ffi::XIValuatorClass => { - let info = unsafe { - mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIValuatorClassInfo>(class) - }; - if let Some(&mut (_, ref mut axis)) = self - .scroll_axes - .iter_mut() - .find(|&&mut (axis, _)| axis == info.number) - { - axis.position = info.value; - } + if class._type == ffi::XIValuatorClass { + let info = unsafe { + mem::transmute::<&ffi::XIAnyClassInfo, &ffi::XIValuatorClassInfo>(class) + }; + if let Some(&mut (_, ref mut axis)) = self + .scroll_axes + .iter_mut() + .find(|&&mut (axis, _)| axis == info.number) + { + axis.position = info.value; } - _ => {} } } } diff --git a/src/platform_impl/linux/x11/monitor.rs b/src/platform_impl/linux/x11/monitor.rs index 274e0cda9f..2bd0ab17fb 100644 --- a/src/platform_impl/linux/x11/monitor.rs +++ b/src/platform_impl/linux/x11/monitor.rs @@ -90,7 +90,7 @@ impl Eq for MonitorHandle {} impl PartialOrd for MonitorHandle { fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(&other)) + Some(self.cmp(other)) } } @@ -204,7 +204,7 @@ impl XConnection { let overlapping_area = window_rect.get_overlapping_area(&monitor.rect); if overlapping_area > largest_overlap { largest_overlap = overlapping_area; - matched_monitor = &monitor; + matched_monitor = monitor; } } @@ -242,8 +242,11 @@ impl XConnection { if is_active { let is_primary = *(*crtc).outputs.offset(0) == primary; has_primary |= is_primary; - MonitorHandle::new(self, resources, crtc_id, crtc, is_primary) - .map(|monitor_id| available.push(monitor_id)); + if let Some(monitor_id) = + MonitorHandle::new(self, resources, crtc_id, crtc, is_primary) + { + available.push(monitor_id) + } } (self.xrandr.XRRFreeCrtcInfo)(crtc); } diff --git a/src/platform_impl/linux/x11/util/format.rs b/src/platform_impl/linux/x11/util/format.rs index 1ab5e01f7e..997946b1ee 100644 --- a/src/platform_impl/linux/x11/util/format.rs +++ b/src/platform_impl/linux/x11/util/format.rs @@ -23,9 +23,9 @@ impl Format { pub fn get_actual_size(&self) -> usize { match self { - &Format::Char => mem::size_of::(), - &Format::Short => mem::size_of::(), - &Format::Long => mem::size_of::(), + Format::Char => mem::size_of::(), + Format::Short => mem::size_of::(), + Format::Long => mem::size_of::(), } } } diff --git a/src/platform_impl/linux/x11/util/geometry.rs b/src/platform_impl/linux/x11/util/geometry.rs index d8f466fc2a..17aeca5584 100644 --- a/src/platform_impl/linux/x11/util/geometry.rs +++ b/src/platform_impl/linux/x11/util/geometry.rs @@ -248,7 +248,7 @@ impl XConnection { ); // The list of children isn't used - if children != ptr::null_mut() { + if !children.is_null() { (self.xlib.XFree)(children as *mut _); } diff --git a/src/platform_impl/linux/x11/util/icon.rs b/src/platform_impl/linux/x11/util/icon.rs index eb13d48b5b..b0253e1b96 100644 --- a/src/platform_impl/linux/x11/util/icon.rs +++ b/src/platform_impl/linux/x11/util/icon.rs @@ -27,7 +27,7 @@ impl Icon { data.push(rgba_icon.height as Cardinal); let pixels = rgba_icon.rgba.as_ptr() as *const Pixel; for pixel_index in 0..pixel_count { - let pixel = unsafe { &*pixels.offset(pixel_index as isize) }; + let pixel = unsafe { &*pixels.add(pixel_index) }; data.push(pixel.to_packed_argb()); } data diff --git a/src/platform_impl/linux/x11/util/keys.rs b/src/platform_impl/linux/x11/util/keys.rs index fc0c9d9062..e6b6e7a147 100644 --- a/src/platform_impl/linux/x11/util/keys.rs +++ b/src/platform_impl/linux/x11/util/keys.rs @@ -36,7 +36,7 @@ impl Iterator for KeymapIter<'_> { fn next(&mut self) -> Option { if self.item.is_none() { - while let Some((index, &item)) = self.iter.next() { + for (index, &item) in self.iter.by_ref() { if item != 0 { self.index = index; self.item = Some(item); diff --git a/src/platform_impl/linux/x11/util/modifiers.rs b/src/platform_impl/linux/x11/util/modifiers.rs index 7c951997ad..acdab577e0 100644 --- a/src/platform_impl/linux/x11/util/modifiers.rs +++ b/src/platform_impl/linux/x11/util/modifiers.rs @@ -151,7 +151,7 @@ impl ModifierKeyState { pub fn key_release(&mut self, keycode: ffi::KeyCode) { if let Some(modifier) = self.keys.remove(&keycode) { - if self.keys.values().find(|&&m| m == modifier).is_none() { + if !self.keys.values().any(|&m| m == modifier) { set_modifier(&mut self.state, modifier, false); } } diff --git a/src/platform_impl/linux/x11/util/randr.rs b/src/platform_impl/linux/x11/util/randr.rs index 0013b901d7..cb380c7d41 100644 --- a/src/platform_impl/linux/x11/util/randr.rs +++ b/src/platform_impl/linux/x11/util/randr.rs @@ -39,15 +39,15 @@ impl XConnection { pub unsafe fn get_xft_dpi(&self) -> Option { (self.xlib.XrmInitialize)(); let resource_manager_str = (self.xlib.XResourceManagerString)(self.display); - if resource_manager_str == ptr::null_mut() { + if resource_manager_str.is_null() { return None; } if let Ok(res) = ::std::ffi::CStr::from_ptr(resource_manager_str).to_str() { let name: &str = "Xft.dpi:\t"; - for pair in res.split("\n") { + for pair in res.split('\n') { if pair.starts_with(&name) { let res = &pair[name.len()..]; - return f64::from_str(&res).ok(); + return f64::from_str(res).ok(); } } } diff --git a/src/platform_impl/linux/x11/util/window_property.rs b/src/platform_impl/linux/x11/util/window_property.rs index 34977f36d2..8bf718ea8e 100644 --- a/src/platform_impl/linux/x11/util/window_property.rs +++ b/src/platform_impl/linux/x11/util/window_property.rs @@ -97,7 +97,7 @@ impl XConnection { quantity_returned, new_data, );*/ - data.extend_from_slice(&new_data); + data.extend_from_slice(new_data); // Fun fact: XGetWindowProperty allocates one extra byte at the end. (self.xlib.XFree)(buf as _); // Don't try to access new_data after this. } else { diff --git a/src/platform_impl/linux/x11/util/wm.rs b/src/platform_impl/linux/x11/util/wm.rs index 693bc5c02d..6fef5a3c4d 100644 --- a/src/platform_impl/linux/x11/util/wm.rs +++ b/src/platform_impl/linux/x11/util/wm.rs @@ -62,11 +62,7 @@ impl XConnection { let wm_check = result.ok().and_then(|wm_check| wm_check.get(0).cloned()); - if let Some(wm_check) = wm_check { - wm_check - } else { - return None; - } + wm_check? }; // Querying the same property on the child window we were given, we should get this child @@ -76,11 +72,7 @@ impl XConnection { let wm_check = result.ok().and_then(|wm_check| wm_check.get(0).cloned()); - if let Some(wm_check) = wm_check { - wm_check - } else { - return None; - } + wm_check? }; // These values should be the same. diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index 35beb01441..45759b05b2 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -150,7 +150,7 @@ impl UnownedWindow { let position = window_attrs .position - .map(|position| position.to_physical::(scale_factor).into()); + .map(|position| position.to_physical::(scale_factor)); let dimensions = { // x11 only applies constraints when the window is actively resized @@ -184,7 +184,7 @@ impl UnownedWindow { // creating let (visual, depth, require_colormap) = match pl_attribs.visual_infos { Some(vi) => (vi.visual, vi.depth, false), - None if window_attrs.transparent == true => { + None if window_attrs.transparent => { // Find a suitable visual let mut vinfo = MaybeUninit::uninit(); let vinfo_initialized = unsafe { @@ -341,7 +341,9 @@ impl UnownedWindow { } //.queue(); } - window.set_pid().map(|flusher| flusher.queue()); + if let Some(flusher) = window.set_pid() { + flusher.queue() + } window.set_window_types(pl_attribs.x11_window_types).queue(); @@ -430,8 +432,7 @@ impl UnownedWindow { } // Select XInput2 events - let mask = { - let mask = ffi::XI_MotionMask + let mask = ffi::XI_MotionMask | ffi::XI_ButtonPressMask | ffi::XI_ButtonReleaseMask //| ffi::XI_KeyPressMask @@ -443,8 +444,6 @@ impl UnownedWindow { | ffi::XI_TouchBeginMask | ffi::XI_TouchUpdateMask | ffi::XI_TouchEndMask; - mask - }; xconn .select_xinput_events(window.xwindow, ffi::XIAllMasterDevices, mask) .queue(); @@ -467,9 +466,10 @@ impl UnownedWindow { window.set_maximized_inner(window_attrs.maximized).queue(); } if window_attrs.fullscreen.is_some() { - window - .set_fullscreen_inner(window_attrs.fullscreen.clone()) - .map(|flusher| flusher.queue()); + if let Some(flusher) = window.set_fullscreen_inner(window_attrs.fullscreen.clone()) + { + flusher.queue() + } if let Some(PhysicalPosition { x, y }) = position { let shared_state = window.shared_state.get_mut();