Fix several clippy lints

This commit is contained in:
Victor Berger 2021-06-09 22:46:09 +02:00 committed by Victor Berger
parent c630bd9086
commit 9ad0edd2a3
18 changed files with 99 additions and 47 deletions

View File

@ -46,7 +46,7 @@ impl<Backend> AnvilState<Backend> {
// only process special actions on key press, not release
return KeyAction::None;
}
return action;
action
}
fn on_pointer_button<B: InputBackend>(&mut self, evt: B::PointerButtonEvent) {
@ -223,7 +223,7 @@ impl AnvilState<UdevData> {
}
fn clamp_coords(&self, pos: (f64, f64)) -> (f64, f64) {
if self.backend_data.output_map.len() == 0 {
if self.backend_data.output_map.is_empty() {
return pos;
}

View File

@ -189,7 +189,7 @@ pub fn run_winit(
Ok(())
})
.map_err(Into::<SwapBuffersError>::into)
.and_then(|x| x.into());
.and_then(|x| x);
renderer.window().set_cursor_visible(cursor_visible);

View File

@ -152,7 +152,7 @@ impl DmabufBuilder {
///
/// Returns `None` if the builder has no planes attached.
pub fn build(mut self) -> Option<Dmabuf> {
if self.internal.planes.len() == 0 {
if self.internal.planes.is_empty() {
return None;
}
@ -167,7 +167,7 @@ impl Dmabuf {
// Note: the `src` Buffer is only used a reference for size and format.
// The contents are determined by the provided file descriptors, which
// do not need to refer to the same buffer `src` does.
pub fn new_from_buffer(src: &impl Buffer, flags: DmabufFlags) -> DmabufBuilder {
pub fn builder_from_buffer(src: &impl Buffer, flags: DmabufFlags) -> DmabufBuilder {
DmabufBuilder {
internal: DmabufInternal {
planes: Vec::with_capacity(MAX_PLANES),
@ -179,8 +179,8 @@ impl Dmabuf {
}
}
/// Create a new Dmabuf
pub fn new(width: u32, height: u32, format: Fourcc, flags: DmabufFlags) -> DmabufBuilder {
/// Create a new Dmabuf builder
pub fn builder(width: u32, height: u32, format: Fourcc, flags: DmabufFlags) -> DmabufBuilder {
DmabufBuilder {
internal: DmabufInternal {
planes: Vec::with_capacity(MAX_PLANES),
@ -198,17 +198,17 @@ impl Dmabuf {
}
/// Returns raw handles of the planes of this buffer
pub fn handles<'a>(&'a self) -> impl Iterator<Item = RawFd> + 'a {
pub fn handles(&self) -> impl Iterator<Item = RawFd> + '_ {
self.0.planes.iter().map(|p| *p.fd.as_ref().unwrap())
}
/// Returns offsets for the planes of this buffer
pub fn offsets<'a>(&'a self) -> impl Iterator<Item = u32> + 'a {
pub fn offsets(&self) -> impl Iterator<Item = u32> + '_ {
self.0.planes.iter().map(|p| p.offset)
}
/// Returns strides for the planes of this buffer
pub fn strides<'a>(&'a self) -> impl Iterator<Item = u32> + 'a {
pub fn strides(&self) -> impl Iterator<Item = u32> + '_ {
self.0.planes.iter().map(|p| p.stride)
}

View File

@ -99,7 +99,7 @@ impl<T> AsDmabuf for GbmBuffer<T> {
return Err(GbmConvertError::InvalidFD);
}
let mut builder = Dmabuf::new_from_buffer(self, DmabufFlags::empty());
let mut builder = Dmabuf::builder_from_buffer(self, DmabufFlags::empty());
for idx in 0..planes {
builder.add_plane(
self.fd()?,

View File

@ -172,10 +172,10 @@ where
debug!(logger, "Success, choosen format: {:?}", format);
let buffers = Buffers::new(drm.clone(), gbm, buffer);
Ok(DrmRenderSurface {
drm,
renderer,
swapchain,
buffers,
swapchain,
renderer,
drm,
})
}
Err(err) => {
@ -337,12 +337,14 @@ impl<A: AsRawFd + 'static> Drop for FbHandle<A> {
}
}
type DmabufSlot<B, D> = Slot<B, (Dmabuf, BufferObject<FbHandle<D>>)>;
struct Buffers<D: AsRawFd + 'static, B: Buffer> {
gbm: GbmDevice<gbm::FdWrapper>,
drm: Arc<DrmSurface<D>>,
_current_fb: Slot<B, (Dmabuf, BufferObject<FbHandle<D>>)>,
pending_fb: Option<Slot<B, (Dmabuf, BufferObject<FbHandle<D>>)>>,
queued_fb: Option<Slot<B, (Dmabuf, BufferObject<FbHandle<D>>)>>,
_current_fb: DmabufSlot<B, D>,
pending_fb: Option<DmabufSlot<B, D>>,
queued_fb: Option<DmabufSlot<B, D>>,
}
impl<D, B> Buffers<D, B>

View File

@ -280,7 +280,7 @@ impl<A: AsRawFd + 'static> DrmSurface<A> {
.iter()
.find(|handle| {
// get information of that property
if let Some(info) = self.get_property(**handle).ok() {
if let Ok(info) = self.get_property(**handle) {
// to find out, if we got the handle of the "IN_FORMATS" property ...
if info.name().to_str().map(|x| x == "IN_FORMATS").unwrap_or(false) {
// so we can use that to get formats

View File

@ -120,7 +120,7 @@ impl<'a> Debug for EGLPlatform<'a> {
/// Trait describing platform specific functionality to create a valid `EGLDisplay` using the `EGL_EXT_platform_base`(https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_platform_base.txt) extension.
pub trait EGLNativeDisplay: Send {
/// List of supported platforms that can be used to create a display using [`eglGetPlatformDisplayEXT`](https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_platform_base.txt)
fn supported_platforms<'a>(&'a self) -> Vec<EGLPlatform<'a>>;
fn supported_platforms(&self) -> Vec<EGLPlatform<'_>>;
/// Type of surfaces created
fn surface_type(&self) -> ffi::EGLint {
@ -130,7 +130,7 @@ pub trait EGLNativeDisplay: Send {
#[cfg(feature = "backend_gbm")]
impl<A: AsRawFd + Send + 'static> EGLNativeDisplay for GbmDevice<A> {
fn supported_platforms<'a>(&'a self) -> Vec<EGLPlatform<'a>> {
fn supported_platforms(&self) -> Vec<EGLPlatform<'_>> {
vec![
// see: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_platform_gbm.txt
egl_platform!(PLATFORM_GBM_KHR, self.as_raw(), &["EGL_KHR_platform_gbm"]),
@ -142,7 +142,7 @@ impl<A: AsRawFd + Send + 'static> EGLNativeDisplay for GbmDevice<A> {
#[cfg(feature = "backend_winit")]
impl EGLNativeDisplay for WinitWindow {
fn supported_platforms<'a>(&'a self) -> Vec<EGLPlatform<'a>> {
fn supported_platforms(&self) -> Vec<EGLPlatform<'_>> {
if let Some(display) = self.wayland_display() {
vec![
// see: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_platform_wayland.txt

View File

@ -537,7 +537,7 @@ impl ImportShm for Gles2Renderer {
unsafe { self.gl.GenTextures(1, &mut tex) };
// new texture, upload in full
upload_full = true;
let texture = Rc::new(Gles2TextureInternal {
Rc::new(Gles2TextureInternal {
texture: tex,
texture_kind: shader_idx,
is_external: false,
@ -546,8 +546,7 @@ impl ImportShm for Gles2Renderer {
height: height as u32,
egl_images: None,
destruction_callback_sender: self.destruction_callback_sender.clone(),
});
texture
})
}),
);

View File

@ -3,3 +3,15 @@
mod rectangle;
pub use self::rectangle::Rectangle;
/// This resource is not managed by Smithay
#[derive(Debug)]
pub struct UnmanagedResource;
impl std::fmt::Display for UnmanagedResource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("This resource is not managed by Smithay.")
}
}
impl std::error::Error for UnmanagedResource {}

View File

@ -7,8 +7,8 @@ use wayland_server::{
use super::{
tree::{Location, SurfaceData},
BufferAssignment, CompositorToken, Damage, Rectangle, RectangleKind, RegionAttributes, Role, RoleType,
SubsurfaceRole, SurfaceEvent,
AlreadyHasRole, BufferAssignment, CompositorToken, Damage, Rectangle, RectangleKind, RegionAttributes,
Role, RoleType, SubsurfaceRole, SurfaceEvent,
};
/*
@ -65,11 +65,11 @@ impl<R> SurfaceImplem<R>
where
R: 'static,
{
fn receive_surface_request<'a>(
fn receive_surface_request(
&mut self,
req: wl_surface::Request,
surface: wl_surface::WlSurface,
ddata: DispatchData<'a>,
ddata: DispatchData<'_>,
) {
match req {
wl_surface::Request::Attach { buffer, x, y } => {
@ -196,7 +196,7 @@ where
{
subcompositor.quick_assign(move |subcompositor, request, _| match request {
wl_subcompositor::Request::GetSubsurface { id, surface, parent } => {
if let Err(()) = SurfaceData::<R>::set_parent(&surface, &parent) {
if let Err(AlreadyHasRole) = SurfaceData::<R>::set_parent(&surface, &parent) {
subcompositor.as_ref().post_error(
wl_subcompositor::Error::BadSurface as u32,
"Surface already has a role.".into(),

View File

@ -76,7 +76,7 @@ mod tree;
pub use self::tree::TraversalAction;
use self::{
roles::{Role, RoleType, WrongRole},
roles::{AlreadyHasRole, Role, RoleType, WrongRole},
tree::SurfaceData,
};
use crate::utils::Rectangle;
@ -433,7 +433,7 @@ impl<R: RoleType + 'static> CompositorToken<R> {
///
/// If the surface is not managed by the `CompositorGlobal` that provided this token, this
/// will panic (having more than one compositor is not supported).
pub fn give_role<RoleData>(self, surface: &WlSurface) -> Result<(), ()>
pub fn give_role<RoleData>(self, surface: &WlSurface) -> Result<(), AlreadyHasRole>
where
R: Role<RoleData>,
RoleData: Default,

View File

@ -92,6 +92,30 @@
#[derive(Debug)]
pub struct WrongRole;
impl std::fmt::Display for WrongRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Wrong role for surface.")
}
}
impl std::error::Error for WrongRole {}
/// An error type signifying that the surface already has a role and
/// cannot be assigned an other
///
/// Generated if you attempt a role operation on a surface that does
/// not have the role you asked for.
#[derive(Debug)]
pub struct AlreadyHasRole;
impl std::fmt::Display for AlreadyHasRole {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("Surface already has a role.")
}
}
impl std::error::Error for AlreadyHasRole {}
/// A trait representing a type that can manage surface roles
pub trait RoleType {
/// Check if the associated surface has a role
@ -126,11 +150,11 @@ pub trait Role<R>: RoleType {
/// Set the role for the associated surface with default associated data
///
/// Fails if the surface already has a role
fn set(&mut self) -> Result<(), ()>
fn set(&mut self) -> Result<(), AlreadyHasRole>
where
R: Default,
{
self.set_with(Default::default()).map_err(|_| ())
self.set_with(Default::default()).map_err(|_| AlreadyHasRole)
}
/// Set the role for the associated surface with given data

View File

@ -127,7 +127,7 @@ impl<R: RoleType + 'static> SurfaceData<R> {
}
/// Register that this surface has a role, fails if it already has one
pub fn give_role<RoleData>(surface: &WlSurface) -> Result<(), ()>
pub fn give_role<RoleData>(surface: &WlSurface) -> Result<(), AlreadyHasRole>
where
R: Role<RoleData>,
RoleData: Default,
@ -215,12 +215,12 @@ impl<R: RoleType + Role<SubsurfaceRole> + 'static> SurfaceData<R> {
///
/// if this surface already has a role, does nothing and fails, otherwise
/// its role is now to be a subsurface
pub fn set_parent(child: &WlSurface, parent: &WlSurface) -> Result<(), ()> {
pub fn set_parent(child: &WlSurface, parent: &WlSurface) -> Result<(), AlreadyHasRole> {
debug_assert!(child.as_ref().is_alive());
debug_assert!(parent.as_ref().is_alive());
// ensure the child is not already a parent of the parent
if Self::is_ancestor(child, parent) {
return Err(());
return Err(AlreadyHasRole);
}
// change child's parent

View File

@ -44,9 +44,9 @@ pub(crate) fn implement_data_source(src: Main<WlDataSource>) -> WlDataSource {
pub fn with_source_metadata<T, F: FnOnce(&SourceMetadata) -> T>(
source: &WlDataSource,
f: F,
) -> Result<T, ()> {
) -> Result<T, crate::utils::UnmanagedResource> {
match source.as_ref().user_data().get::<RefCell<SourceMetadata>>() {
Some(data) => Ok(f(&data.borrow())),
None => Err(()),
None => Err(crate::utils::UnmanagedResource),
}
}

View File

@ -251,7 +251,7 @@ fn implement_dnd_data_offer(
match req {
Request::Accept { mime_type, .. } => {
if let Some(mtype) = mime_type {
if let Err(()) = with_source_metadata(&source, |meta| {
if let Err(crate::utils::UnmanagedResource) = with_source_metadata(&source, |meta| {
data.accepted = meta.mime_types.contains(&mtype);
}) {
data.accepted = false;

View File

@ -259,7 +259,7 @@ where
return;
}
let mut buf = Dmabuf::new(
let mut buf = Dmabuf::builder(
width as u32,
height as u32,
format,
@ -277,7 +277,7 @@ where
None => {
params.as_ref().post_error(
ParamError::Incomplete as u32,
format!("Provided buffer is incomplete, it has zero planes"),
"Provided buffer is incomplete, it has zero planes".to_string(),
);
return;
}
@ -305,6 +305,7 @@ where
}
}
#[allow(clippy::clippy::too_many_arguments)]
fn create_immed<'a>(
&mut self,
params: &BufferParams,
@ -348,7 +349,7 @@ where
return;
}
let mut buf = Dmabuf::new(
let mut buf = Dmabuf::builder(
width as u32,
height as u32,
format,
@ -366,7 +367,7 @@ where
None => {
params.as_ref().post_error(
ParamError::Incomplete as u32,
format!("Provided buffer is incomplete, it has zero planes"),
"Provided buffer is incomplete, it has zero planes".to_string(),
);
return;
}

View File

@ -61,7 +61,7 @@
//! the contents of sync_state
//! */
//! },
//! Err(()) => {
//! Err(NoExplicitSync) => {
//! /* This surface is not explicitly synchronized, nothing more to do
//! */
//! }
@ -155,6 +155,18 @@ pub enum ExplicitSyncError {
NoBuffer,
}
/// This surface is not explicitly synchronized
#[derive(Debug)]
pub struct NoExplicitSync;
impl std::fmt::Display for NoExplicitSync {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("The surface is not explicitly synchronized.")
}
}
impl std::error::Error for NoExplicitSync {}
/// Retrieve the explicit synchronization state commited by the client
///
/// This state can contain an acquire fence and a release object, for synchronization (see module-level docs).
@ -163,12 +175,14 @@ pub enum ExplicitSyncError {
/// should always call it on surface commit to avoid getting out-of-sync with the client.
///
/// This function returns an error if the client has not setup explicit synchronization for this surface.
pub fn get_explicit_synchronization_state(attrs: &mut SurfaceAttributes) -> Result<ExplicitSyncState, ()> {
pub fn get_explicit_synchronization_state(
attrs: &mut SurfaceAttributes,
) -> Result<ExplicitSyncState, NoExplicitSync> {
attrs
.user_data
.get::<ESUserData>()
.and_then(|s| s.take_state())
.ok_or(())
.ok_or(NoExplicitSync)
}
/// Send a synchronization error to a client

View File

@ -192,7 +192,7 @@ fn launch<Data: Any>(inner: &Rc<RefCell<Inner<Data>>>) -> std::io::Result<()> {
client.data_map().insert_if_missing(|| idle_inner.clone());
client.add_destructor(Filter::new(|e: Arc<_>, _, _| client_destroy::<Data>(&e)));
instance.wayland_client = Some(client.clone());
instance.wayland_client = Some(client);
}
});