From 2dd6137459a885f5ee318980c2b718d4dc5551a2 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 18 Oct 2024 10:11:22 -0400 Subject: [PATCH] clippy --- accessibility/src/id.rs | 10 +++++----- core/src/clipboard.rs | 17 ++++++----------- core/src/element.rs | 2 +- core/src/id.rs | 10 +++++----- core/src/overlay/group.rs | 1 - core/src/widget/tree.rs | 4 ++-- runtime/src/dnd.rs | 4 ++-- src/lib.rs | 2 +- tiny_skia/src/engine.rs | 2 +- tiny_skia/src/layer.rs | 2 +- widget/src/button.rs | 2 +- widget/src/checkbox.rs | 2 +- widget/src/container.rs | 2 +- widget/src/mouse_area.rs | 25 ++++++++++++------------- widget/src/pane_grid/content.rs | 2 -- widget/src/pane_grid/title_bar.rs | 2 -- widget/src/row.rs | 2 +- widget/src/scrollable.rs | 2 +- widget/src/tooltip.rs | 2 +- 19 files changed, 42 insertions(+), 53 deletions(-) diff --git a/accessibility/src/id.rs b/accessibility/src/id.rs index e4042e34..1d80bbd8 100644 --- a/accessibility/src/id.rs +++ b/accessibility/src/id.rs @@ -137,12 +137,12 @@ impl From for u64 { } } -impl ToString for Id { - fn to_string(&self) -> String { +impl std::fmt::Display for Id { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self.0 { - Internal::Unique(_) => "Undefined".to_string(), - Internal::Custom(_, id) => id.to_string(), - Internal::Set(_) => "Set".to_string(), + Internal::Unique(_) => write!(f, "Undefined"), + Internal::Custom(_, id) => write!(f, "{}", id.to_string()), + Internal::Set(_) => write!(f, "Set"), } } } diff --git a/core/src/clipboard.rs b/core/src/clipboard.rs index caf0b938..b71aef2b 100644 --- a/core/src/clipboard.rs +++ b/core/src/clipboard.rs @@ -69,7 +69,7 @@ pub trait Clipboard { /// Reads the current content of the [`Clipboard`] as text. fn read_data( &self, - kind: Kind, + _kind: Kind, _mimes: Vec, ) -> Option<(Vec, String)> { None @@ -78,7 +78,7 @@ pub trait Clipboard { /// Writes the given contents to the [`Clipboard`]. fn write_data( &mut self, - kind: Kind, + _kind: Kind, _contents: ClipboardStoreData< Box, >, @@ -119,7 +119,7 @@ pub trait Clipboard { } /// Request window size - fn request_logical_window_size(&self, width: f32, height: f32) {} + fn request_logical_window_size(&self, _width: f32, _height: f32) {} } /// The kind of [`Clipboard`]. @@ -187,10 +187,7 @@ pub fn peek_dnd( clipboard: &mut dyn Clipboard, mime: Option, ) -> Option { - let Some(mime) = mime.or_else(|| T::allowed().first().cloned().into()) - else { - return None; - }; + let mime = mime.or_else(|| T::allowed().first().cloned())?; clipboard .peek_dnd(mime) .and_then(|data| T::try_from(data).ok()) @@ -206,7 +203,7 @@ pub enum DndSource { } /// A list of DnD destination rectangles. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct DndDestinationRectangles { /// The rectangle of the DnD destination. rectangles: Vec, @@ -215,9 +212,7 @@ pub struct DndDestinationRectangles { impl DndDestinationRectangles { /// Creates a new [`DndDestinationRectangles`]. pub fn new() -> Self { - Self { - rectangles: Vec::new(), - } + Self::default() } /// Creates a new [`DndDestinationRectangles`] with the given capacity. diff --git a/core/src/element.rs b/core/src/element.rs index 6a45aa83..f97ed6bc 100644 --- a/core/src/element.rs +++ b/core/src/element.rs @@ -311,7 +311,7 @@ where } fn diff(&mut self, tree: &mut Tree) { - self.widget.diff(tree) + self.widget.diff(tree); } fn size(&self) -> Size { diff --git a/core/src/id.rs b/core/src/id.rs index 60862670..2b6927bb 100644 --- a/core/src/id.rs +++ b/core/src/id.rs @@ -75,12 +75,12 @@ impl From for NonZeroU128 { } } -impl ToString for Id { - fn to_string(&self) -> String { +impl std::fmt::Display for Id { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self.0 { - Internal::Unique(_) => "Undefined".to_string(), - Internal::Custom(_, id) => id.to_string(), - Internal::Set(_) => "Set".to_string(), + Internal::Unique(_) => write!(f, "Undefined"), + Internal::Custom(_, id) => write!(f, "{}", id.to_string()), + Internal::Set(_) => write!(f, "Set"), } } } diff --git a/core/src/overlay/group.rs b/core/src/overlay/group.rs index f80af3b2..ec0906e7 100644 --- a/core/src/overlay/group.rs +++ b/core/src/overlay/group.rs @@ -3,7 +3,6 @@ use crate::mouse; use crate::overlay; use crate::renderer; use crate::widget; -use crate::widget::Operation; use crate::{Clipboard, Event, Layout, Overlay, Point, Rectangle, Shell, Size}; /// An [`Overlay`] container that displays multiple overlay [`overlay::Element`] diff --git a/core/src/widget/tree.rs b/core/src/widget/tree.rs index 00b0be1e..69deee51 100644 --- a/core/src/widget/tree.rs +++ b/core/src/widget/tree.rs @@ -269,13 +269,13 @@ impl Tree { new_children.iter().map(|c| c.borrow().id()).collect(), |tree, widget| { let borrowed: &mut dyn Widget<_, _, _> = widget.borrow_mut(); - tree.diff(borrowed) + tree.diff(borrowed); }, |widget| { let borrowed: &dyn Widget<_, _, _> = widget.borrow(); Self::new(borrowed) }, - ) + ); } /// Reconciles the children of the tree with the provided list of widgets using custom diff --git a/runtime/src/dnd.rs b/runtime/src/dnd.rs index 0461bece..69c956f6 100644 --- a/runtime/src/dnd.rs +++ b/runtime/src/dnd.rs @@ -80,8 +80,8 @@ pub fn peek_dnd() -> Task> { task::oneshot(|tx| { Action::Dnd(DndAction::PeekDnd( T::allowed() - .get(0) - .map_or_else(|| String::new(), |s| s.to_string()), + .first() + .map_or_else(String::new, std::string::ToString::to_string), tx, )) }) diff --git a/src/lib.rs b/src/lib.rs index 0964ffa4..cc5a4465 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -700,7 +700,7 @@ pub type Element< /// The result of running an iced program. pub type Result = std::result::Result<(), Error>; -#[cfg(any(feature = "winit"))] +#[cfg(feature = "winit")] /// Runs a basic iced application with default [`Settings`] given its title, /// update, and view logic. /// diff --git a/tiny_skia/src/engine.rs b/tiny_skia/src/engine.rs index e5d3b65d..2f05e760 100644 --- a/tiny_skia/src/engine.rs +++ b/tiny_skia/src/engine.rs @@ -620,7 +620,7 @@ impl Engine { let center = physical_bounds.center(); let radians = f32::from(svg.rotation); - let transform = Transform::default().post_rotate_at( + let transform = tiny_skia::Transform::default().post_rotate_at( radians.to_degrees(), center.x, center.y, diff --git a/tiny_skia/src/layer.rs b/tiny_skia/src/layer.rs index 3774762f..56b70b2c 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -1,7 +1,7 @@ use crate::Primitive; use crate::core::renderer::Quad; use crate::core::{ - self, Background, Color, Point, Radians, Rectangle, Svg, Transformation, + self, Background, Color, Point, Rectangle, Svg, Transformation, }; use crate::graphics::damage; use crate::graphics::layer; diff --git a/widget/src/button.rs b/widget/src/button.rs index 6fb43be5..b284f5d6 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -289,7 +289,7 @@ where } fn diff(&mut self, tree: &mut Tree) { - tree.diff_children(std::slice::from_mut(&mut self.content)) + tree.diff_children(std::slice::from_mut(&mut self.content)); } fn size(&self) -> Size { diff --git a/widget/src/checkbox.rs b/widget/src/checkbox.rs index e3c26c58..1deabe65 100644 --- a/widget/src/checkbox.rs +++ b/widget/src/checkbox.rs @@ -461,7 +461,7 @@ where size, line_height, shaping, - wrap, + wrap: _, } = &self.icon; let size = size.unwrap_or(Pixels(bounds.height * 0.7)); diff --git a/widget/src/container.rs b/widget/src/container.rs index 44886f09..c3818bae 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -592,7 +592,7 @@ pub fn visible_bounds(id: Id) -> Task> { } task::widget(VisibleBounds { - target: id.into(), + target: id, depth: 0, scrollables: Vec::new(), bounds: None, diff --git a/widget/src/mouse_area.rs b/widget/src/mouse_area.rs index c0e3cc61..3a4e2c83 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -164,11 +164,11 @@ impl Default for State { fn default() -> Self { Self { is_hovered: Default::default(), - drag_initiated: Default::default(), + drag_initiated: None, is_out_of_bounds: true, - last_click: Default::default(), + last_click: None, cursor_position: None, - bounds: Default::default(), + bounds: Rectangle::default(), previous_click: None, } } @@ -351,7 +351,7 @@ where renderer: &Renderer, dnd_rectangles: &mut crate::core::clipboard::DndDestinationRectangles, ) { - if let Some(state) = state.children.iter().next() { + if let Some(state) = state.children.first() { self.content.as_widget().drag_destinations( state, layout, @@ -420,20 +420,19 @@ fn update( } if !cursor.is_over(layout.bounds()) { - if !state.is_out_of_bounds { - if widget + if !state.is_out_of_bounds + && widget .on_enter .as_ref() .or(widget.on_exit.as_ref()) .is_some() - { - if let Event::Mouse(mouse::Event::CursorMoved { .. }) = event { - state.is_out_of_bounds = true; - if let Some(message) = widget.on_exit.as_ref() { - shell.publish(message.clone()); - } - return; + { + if let Event::Mouse(mouse::Event::CursorMoved { .. }) = event { + state.is_out_of_bounds = true; + if let Some(message) = widget.on_exit.as_ref() { + shell.publish(message.clone()); } + return; } } diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs index 3400bd3e..a06cbba7 100644 --- a/widget/src/pane_grid/content.rs +++ b/widget/src/pane_grid/content.rs @@ -1,5 +1,3 @@ -use iced_renderer::core::widget::Operation; - use crate::container; use crate::core::layout; use crate::core::mouse; diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs index c451b6b1..4181f24d 100644 --- a/widget/src/pane_grid/title_bar.rs +++ b/widget/src/pane_grid/title_bar.rs @@ -1,5 +1,3 @@ -use iced_renderer::core::widget::Operation; - use crate::container; use crate::core::layout; use crate::core::mouse; diff --git a/widget/src/row.rs b/widget/src/row.rs index 9d41b5ae..2178f15d 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -196,7 +196,7 @@ where } fn diff(&mut self, tree: &mut Tree) { - tree.diff_children(&mut self.children) + tree.diff_children(&mut self.children); } fn size(&self) -> Size { diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index f26750be..e5a0ca20 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -470,7 +470,7 @@ where } fn diff(&mut self, tree: &mut Tree) { - tree.diff_children(std::slice::from_mut(&mut self.content)) + tree.diff_children(std::slice::from_mut(&mut self.content)); } fn size(&self) -> Size { diff --git a/widget/src/tooltip.rs b/widget/src/tooltip.rs index 7df6b307..1e72d8b1 100644 --- a/widget/src/tooltip.rs +++ b/widget/src/tooltip.rs @@ -189,7 +189,7 @@ where tree.diff_children(&mut [ self.content.as_widget_mut(), self.tooltip.as_widget_mut(), - ]) + ]); } fn layout(