From 4946017c0c8fae965f30ed0e5199fbfae6a2fe3c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 5 Oct 2017 22:13:14 +0200 Subject: [PATCH] Apply a bunch of clippy suggestions --- src/backend/drm/backend.rs | 15 +++++++-------- src/backend/drm/mod.rs | 25 +++++++++++-------------- src/backend/graphics/egl.rs | 16 ++++++++-------- src/backend/winit.rs | 6 ++---- src/wayland/compositor/handlers.rs | 2 +- src/wayland/compositor/mod.rs | 6 +++--- src/wayland/compositor/roles.rs | 4 ++-- src/wayland/compositor/tree.rs | 29 +++++++++++++---------------- src/wayland/output/mod.rs | 2 +- src/wayland/seat/keyboard.rs | 2 +- src/wayland/seat/mod.rs | 2 +- src/wayland/seat/pointer.rs | 2 +- src/wayland/shell/mod.rs | 8 ++++---- src/wayland/shell/wl_handlers.rs | 11 +++++------ src/wayland/shell/xdg_handlers.rs | 4 ++-- src/wayland/shm/mod.rs | 10 ++++------ 16 files changed, 66 insertions(+), 78 deletions(-) diff --git a/src/backend/drm/backend.rs b/src/backend/drm/backend.rs index a58bff7..d9b66d0 100644 --- a/src/backend/drm/backend.rs +++ b/src/backend/drm/backend.rs @@ -114,7 +114,7 @@ impl DrmBackend { |surface| { // create an egl surface from the gbm one debug!(log, "Creating EGLSurface"); - let egl_surface = context.egl.create_surface(&surface)?; + let egl_surface = context.egl.create_surface(surface)?; // make it active for the first `crtc::set` // (which is needed before the first page_flip) @@ -270,7 +270,7 @@ impl DrmBackend { /// Other errors might occur. pub fn use_mode(&mut self, mode: Mode) -> Result<()> { // check the connectors - for connector in self.connectors.iter() { + for connector in &self.connectors { if !connector::Info::load_from_device(self.graphics.head().head().head(), *connector) .chain_err(|| { ErrorKind::DrmDev(format!("{:?}", self.graphics.head().head().head())) @@ -318,7 +318,7 @@ impl DrmBackend { |surface| { // create an egl surface from the gbm one debug!(logger_ref, "Creating EGLSurface"); - let egl_surface = graphics.context.egl.create_surface(&surface)?; + let egl_surface = graphics.context.egl.create_surface(surface)?; // make it active for the first `crtc::set` // (which is needed before the first page_flip) @@ -383,13 +383,12 @@ impl Drop for DrmBackend { self.graphics.rent_all_mut(|graphics| { if let Some(fb) = graphics.gbm.surface.rent(|egl| { if let Some(mut next) = egl.buffers.next_buffer.take() { - return next.take_userdata(); + next.take_userdata() + } else if let Ok(mut next) = graphics.gbm.surface.head().lock_front_buffer() { + next.take_userdata() } else { - if let Ok(mut next) = graphics.gbm.surface.head().lock_front_buffer() { - return next.take_userdata(); - } + None } - None }) { // ignore failure at this point let _ = framebuffer::destroy(&*graphics.context.devices.drm, fb.handle()); diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index e838f79..2b38eec 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -397,7 +397,7 @@ impl + Borrow + 'static> DrmDevice { let connectors = connectors.into(); // check if we have an encoder for every connector and the mode mode - for connector in connectors.iter() { + for connector in &connectors { let con_info = connector::Info::load_from_device(self.context.head().head(), *connector) .chain_err(|| { ErrorKind::DrmDev(format!("{:?}", self.context.head().head())) @@ -471,7 +471,7 @@ pub trait DrmHandler + 'static> { fn error(&mut self, evlh: &mut EventLoopHandle, device: &mut DrmDevice, error: DrmError); } -/// Bind a `DrmDevice` to an EventLoop, +/// Bind a `DrmDevice` to an `EventLoop`, /// /// This will cause it to recieve events and feed them into an `DrmHandler` pub fn drm_device_bind(evlh: &mut EventLoopHandle, device: DrmDevice, handler: H) @@ -500,21 +500,18 @@ where let events = crtc::receive_events(dev); match events { Ok(events) => for event in events { - match event { - crtc::Event::PageFlip(event) => { - let token = dev.backends.get(&event.crtc).cloned(); - if let Some(token) = token { - // we can now unlock the buffer - evlh.state().get(&token).borrow().unlock_buffer(); - trace!(dev.logger, "Handling event for backend {:?}", event.crtc); - // and then call the user to render the next frame - handler.ready(evlh, dev, &token, event.frame, event.duration); - } + if let crtc::Event::PageFlip(event) = event { + let token = dev.backends.get(&event.crtc).cloned(); + if let Some(token) = token { + // we can now unlock the buffer + evlh.state().get(&token).borrow().unlock_buffer(); + trace!(dev.logger, "Handling event for backend {:?}", event.crtc); + // and then call the user to render the next frame + handler.ready(evlh, dev, &token, event.frame, event.duration); } - _ => {} } }, - Err(err) => return handler.error(evlh, dev, err), + Err(err) => handler.error(evlh, dev, err), }; }, error: |evlh, id, _, error| { diff --git a/src/backend/graphics/egl.rs b/src/backend/graphics/egl.rs index 51fbaeb..994ae98 100644 --- a/src/backend/graphics/egl.rs +++ b/src/backend/graphics/egl.rs @@ -640,7 +640,7 @@ impl<'a, T: NativeSurface> EGLContext<'a, T> { let mut context_attributes = Vec::with_capacity(10); - if egl_version >= (1, 5) || extensions.iter().any(|s| s == &"EGL_KHR_create_context") { + if egl_version >= (1, 5) || extensions.iter().any(|s| *s == "EGL_KHR_create_context") { trace!(log, "Setting CONTEXT_MAJOR_VERSION to {}", version.0); context_attributes.push(ffi::egl::CONTEXT_MAJOR_VERSION as i32); context_attributes.push(version.0 as i32); @@ -728,8 +728,8 @@ impl<'a, T: NativeSurface> EGLContext<'a, T> { self.display, self.config_id, match surface { - NativeSurfacePtr::X11(ptr) => ptr, - NativeSurfacePtr::Wayland(ptr) => ptr, + NativeSurfacePtr::X11(ptr) | + NativeSurfacePtr::Wayland(ptr) | NativeSurfacePtr::Gbm(ptr) => ptr, }, self.surface_attributes.as_ptr(), @@ -743,7 +743,7 @@ impl<'a, T: NativeSurface> EGLContext<'a, T> { debug!(self.logger, "EGL surface successfully created"); Ok(EGLSurface { - context: &self, + context: self, surface: egl_surface, keep, _lifetime_surface: PhantomData, @@ -894,9 +894,9 @@ impl fmt::Display for SwapBuffersError { impl error::Error for SwapBuffersError { fn description(&self) -> &str { - match self { - &SwapBuffersError::ContextLost => "The context has been lost, it needs to be recreated", - &SwapBuffersError::AlreadySwapped => { + match *self { + SwapBuffersError::ContextLost => "The context has been lost, it needs to be recreated", + SwapBuffersError::AlreadySwapped => { "Buffers are already swapped, swap_buffers was called too many times" } } @@ -987,7 +987,7 @@ pub struct PixelFormat { pub srgb: bool, } -/// Trait that describes objects that have an OpenGl context +/// Trait that describes objects that have an OpenGL context /// and can be used to render upon pub trait EGLGraphicsBackend: GraphicsBackend { /// Swaps buffers at the end of a frame. diff --git a/src/backend/winit.rs b/src/backend/winit.rs index f3c971c..f09381d 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -618,8 +618,8 @@ impl InputBackend for WinitInputBackend { let mut handler = self.handler.as_mut(); let logger = &self.logger; - self.events_loop.poll_events(move |event| match event { - Event::WindowEvent { event, .. } => { + self.events_loop.poll_events(move |event| { + if let Event::WindowEvent { event, .. } = event { match (event, handler.as_mut()) { (WindowEvent::Resized(x, y), _) => { trace!(logger, "Resizing window to {:?}", (x, y)); @@ -816,8 +816,6 @@ impl InputBackend for WinitInputBackend { } *time_counter += 1; } - Event::DeviceEvent { .. } => {} - _ => {} }); } diff --git a/src/wayland/compositor/handlers.rs b/src/wayland/compositor/handlers.rs index 110df2c..7cf4df6 100644 --- a/src/wayland/compositor/handlers.rs +++ b/src/wayland/compositor/handlers.rs @@ -79,7 +79,7 @@ impl Clone for SurfaceIData { fn clone(&self) -> SurfaceIData { SurfaceIData { log: self.log.clone(), - implem: self.implem.clone(), + implem: self.implem, idata: self.idata.clone(), } } diff --git a/src/wayland/compositor/mod.rs b/src/wayland/compositor/mod.rs index 504705a..6cdc9b1 100644 --- a/src/wayland/compositor/mod.rs +++ b/src/wayland/compositor/mod.rs @@ -77,7 +77,7 @@ //! the details of what it enables you. //! //! The surface metadata is held in the `SurfaceAttributes` struct. In contains double-buffered -//! state pending from the client as defined by the protocol for wl_surface, as well as your +//! state pending from the client as defined by the protocol for `wl_surface`, as well as your //! user-defined type holding any data you need to have associated with a struct. See its //! documentation for details. //! @@ -240,7 +240,7 @@ impl Default for RegionAttributes { /// A Compositor global token /// /// This token can be cloned at will, and is the entry-point to -/// access data associated with the wl_surface and wl_region managed +/// access data associated with the `wl_surface` and `wl_region` managed /// by the `CompositorGlobal` that provided it. pub struct CompositorToken { _data: ::std::marker::PhantomData<*mut U>, @@ -524,7 +524,7 @@ impl CompositorToken { } } -/// Create new wl_compositor and wl_subcompositor globals. +/// Create new `wl_compositor` and `wl_subcompositor` globals. /// /// The globals are directly registered into the eventloop, and this function /// returns a `CompositorToken` which you'll need access the data associated to diff --git a/src/wayland/compositor/roles.rs b/src/wayland/compositor/roles.rs index 845ffa9..847c48c 100644 --- a/src/wayland/compositor/roles.rs +++ b/src/wayland/compositor/roles.rs @@ -102,9 +102,9 @@ pub trait RoleType { fn has_role(&self) -> bool; } -/// A trait representing the capability of a RoleType to handle a given role +/// A trait representing the capability of a `RoleType` to handle a given role /// -/// This trait allows to interact with the different roles a RoleType can +/// This trait allows to interact with the different roles a `RoleType` can /// handle. /// /// This trait is meant to be used generically, for example, to retrieve the diff --git a/src/wayland/compositor/tree.rs b/src/wayland/compositor/tree.rs index 6d261f8..7cbecc9 100644 --- a/src/wayland/compositor/tree.rs +++ b/src/wayland/compositor/tree.rs @@ -21,8 +21,8 @@ use wayland_server::protocol::wl_surface; /// have a failure case to forbid this. Note that if any node in such a graph does not /// have a parent, then the graph is a tree and this node is its root. /// -/// All the methods here are unsafe, because they assume the provided wl_surface object -/// is correctly initialized regarding its user_data. +/// All the methods here are unsafe, because they assume the provided `wl_surface` object +/// is correctly initialized regarding its `user_data`. pub struct SurfaceData { parent: Option, children: Vec, @@ -369,29 +369,26 @@ impl SurfaceData { let mut data_guard = data_mutex.lock().unwrap(); let data_guard = &mut *data_guard; // call the callback on ourselves - match f( + if let TraversalAction::DoChildren(t) = f( root, &mut data_guard.attributes, &mut data_guard.role, &initial, ) { - TraversalAction::DoChildren(t) => { - // loop over children - if reverse { - for c in data_guard.children.iter().rev() { - if !map::(c, root, &t, &mut f, true) { - break; - } + // loop over children + if reverse { + for c in data_guard.children.iter().rev() { + if !map::(c, root, &t, &mut f, true) { + break; } - } else { - for c in &data_guard.children { - if !map::(c, root, &t, &mut f, false) { - break; - } + } + } else { + for c in &data_guard.children { + if !map::(c, root, &t, &mut f, false) { + break; } } } - _ => {} } } } diff --git a/src/wayland/output/mod.rs b/src/wayland/output/mod.rs index 6dfd1c9..2ac08da 100644 --- a/src/wayland/output/mod.rs +++ b/src/wayland/output/mod.rs @@ -267,7 +267,7 @@ impl Output { /// Chech is given wl_output instance is managed by this `Output`. pub fn owns(&self, output: &wl_output::WlOutput) -> bool { - self.instances.iter().find(|&o| o.equals(output)).is_some() + self.instances.iter().any(|o| o.equals(output)) } /// Cleanup internal `wl_output` instances list diff --git a/src/wayland/seat/keyboard.rs b/src/wayland/seat/keyboard.rs index 9a942cf..4d23023 100644 --- a/src/wayland/seat/keyboard.rs +++ b/src/wayland/seat/keyboard.rs @@ -170,7 +170,7 @@ pub enum Error { /// Create a keyboard handler from a set of RMLVO rules pub(crate) fn create_keyboard_handler(rules: &str, model: &str, layout: &str, variant: &str, options: Option, repeat_delay: i32, repeat_rate: i32, - logger: ::slog::Logger) + logger: &::slog::Logger) -> Result { let log = logger.new(o!("smithay_module" => "xkbcommon_handler")); info!(log, "Initializing a xkbcommon handler with keymap query"; diff --git a/src/wayland/seat/mod.rs b/src/wayland/seat/mod.rs index f7837e8..2b19ef8 100644 --- a/src/wayland/seat/mod.rs +++ b/src/wayland/seat/mod.rs @@ -169,7 +169,7 @@ impl Seat { options, repeat_delay, repeat_rate, - self.log.clone(), + &self.log, )?; if self.keyboard.is_some() { // there is already a keyboard, remove it and notify the clients diff --git a/src/wayland/seat/pointer.rs b/src/wayland/seat/pointer.rs index 43b2599..5c631a0 100644 --- a/src/wayland/seat/pointer.rs +++ b/src/wayland/seat/pointer.rs @@ -64,7 +64,7 @@ impl PointerHandle { // do we leave a surface ? let mut leave = true; if let Some(ref focus) = guard.focus { - if let Some((ref surface, _, _)) = location { + if let Some((surface, _, _)) = location { if focus.equals(surface) { leave = false; } diff --git a/src/wayland/shell/mod.rs b/src/wayland/shell/mod.rs index 6174250..3f8b107 100644 --- a/src/wayland/shell/mod.rs +++ b/src/wayland/shell/mod.rs @@ -251,7 +251,7 @@ impl PopupState { if let Some(p) = self.parent.clone() { Some(PopupState { parent: p, - positioner: self.positioner.clone(), + positioner: self.positioner, }) } else { // the parent surface does no exist any longer, @@ -283,15 +283,15 @@ impl Clone for ShellSurfaceIData { fn clone(&self) -> ShellSurfaceIData { ShellSurfaceIData { log: self.log.clone(), - compositor_token: self.compositor_token.clone(), - implementation: self.implementation.clone(), + compositor_token: self.compositor_token, + implementation: self.implementation, idata: self.idata.clone(), state_token: self.state_token.clone(), } } } -/// Create new xdg_shell and wl_shell globals. +/// Create new `xdg_shell` and `wl_shell` globals. /// /// The globals are directly registered into the eventloop, and this function /// returns a `StateToken<_>` which you'll need access the list of shell diff --git a/src/wayland/shell/wl_handlers.rs b/src/wayland/shell/wl_handlers.rs index 3f77e5b..d2373c3 100644 --- a/src/wayland/shell/wl_handlers.rs +++ b/src/wayland/shell/wl_handlers.rs @@ -72,7 +72,7 @@ where pending_configures: Vec::new(), configured: true, }; - if let Err(_) = idata.compositor_token.give_role_with(surface, role_data) { + if idata.compositor_token.give_role_with(surface, role_data).is_err() { shell.post_error( wl_shell::Error::Role as u32, "Surface already has a role.".into(), @@ -91,7 +91,7 @@ where // register ourselves to the wl_shell for ping handling let mutex = unsafe { &*(shell.get_user_data() as *mut ShellUserData) }; let mut guard = mutex.lock().unwrap(); - if guard.1.len() == 0 && guard.0.pending_ping != 0 { + if guard.1.is_empty() && guard.0.pending_ping != 0 { // there is a pending ping that no surface could receive yet, send it // note this is not possible that it was received and then a wl_shell_surface was // destroyed, because wl_shell_surface has no destructor! @@ -241,7 +241,7 @@ where min_size: (0, 0), max_size: (0, 0), }); - return true; + true }) .expect("xdg_surface exists but surface has not shell_surface role?!"); // we need to notify about this new toplevel surface @@ -419,11 +419,10 @@ where let &(ref surface, _) = unsafe { &*(ptr as *mut ShellSurfaceUserData) }; idata .compositor_token - .with_role_data(surface, |data| match data.pending_state { - ShellSurfacePendingState::Toplevel(ref mut state) => { + .with_role_data(surface, |data| { + if let ShellSurfacePendingState::Toplevel(ref mut state) = data.pending_state { state.title = title; } - _ => {} }) .expect("wl_shell_surface exists but wl_surface has wrong role?!"); }, diff --git a/src/wayland/shell/xdg_handlers.rs b/src/wayland/shell/xdg_handlers.rs index cfbb18e..4400fb0 100644 --- a/src/wayland/shell/xdg_handlers.rs +++ b/src/wayland/shell/xdg_handlers.rs @@ -93,7 +93,7 @@ where pending_configures: Vec::new(), configured: false, }; - if let Err(_) = idata.compositor_token.give_role_with(wl_surface, role_data) { + if idata.compositor_token.give_role_with(wl_surface, role_data).is_err() { shell.post_error( zxdg_shell_v6::Error::Role as u32, "Surface already has a role.".into(), @@ -315,7 +315,7 @@ where .with_role_data::(surface, |data| { data.pending_state = ShellSurfacePendingState::Popup(PopupState { parent: unsafe { parent_surface.clone_unchecked() }, - positioner: positioner_data.clone(), + positioner: *positioner_data, }); }) .expect("xdg_surface exists but surface has not shell_surface role?!"); diff --git a/src/wayland/shm/mod.rs b/src/wayland/shm/mod.rs index c88f3f3..e60a02b 100644 --- a/src/wayland/shm/mod.rs +++ b/src/wayland/shm/mod.rs @@ -71,7 +71,7 @@ use wayland_server::protocol::{wl_buffer, wl_shm, wl_shm_pool}; mod pool; #[derive(Clone)] -/// Internal data storage of ShmGlobal +/// Internal data storage of `ShmGlobal` /// /// This type is only visible as type parameter of /// the `Global` handle you are provided. @@ -104,9 +104,7 @@ where log: log.new(o!("smithay_module" => "shm_handler")), }; - let global = evl.register_global::(1, shm_global_bind, data); - - global + evl.register_global::(1, shm_global_bind, data) } /// Error that can occur when accessing an SHM buffer @@ -125,13 +123,13 @@ pub enum BufferAccessError { /// Call given closure with the contents of the given buffer /// -/// If the buffer is managed by the provided ShmGlobal, its contents are +/// If the buffer is managed by the provided `ShmGlobal`, its contents are /// extracted and the closure is extracted with them: /// /// - The first argument is a data slice of the contents of the pool /// - The second argument is the specification of this buffer is this pool /// -/// If the buffer is not managed by the provided ShmGlobal, the closure is not called +/// If the buffer is not managed by the provided `ShmGlobal`, the closure is not called /// and this method will return `Err(())` (this will be the case for an EGL buffer for example). pub fn with_buffer_contents(buffer: &wl_buffer::WlBuffer, f: F) -> Result<(), BufferAccessError> where