diff --git a/accessibility/src/id.rs b/accessibility/src/id.rs index 752e51c192..e104d5d50c 100644 --- a/accessibility/src/id.rs +++ b/accessibility/src/id.rs @@ -124,12 +124,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 3e7458c024..0197354f67 100644 --- a/core/src/clipboard.rs +++ b/core/src/clipboard.rs @@ -20,7 +20,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 @@ -29,7 +29,7 @@ pub trait Clipboard { /// Writes the given contents to the [`Clipboard`]. fn write_data( &mut self, - kind: Kind, + _kind: Kind, _contents: ClipboardStoreData< Box, >, @@ -70,7 +70,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`]. @@ -141,10 +141,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()) @@ -160,7 +157,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, @@ -169,9 +166,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 3cb0f17a81..c7f8de6701 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 3fc74ce925..8af5d8ab66 100644 --- a/core/src/id.rs +++ b/core/src/id.rs @@ -60,12 +60,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 d31f2234a6..6541d311a0 100644 --- a/core/src/overlay/group.rs +++ b/core/src/overlay/group.rs @@ -4,7 +4,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/renderer/null.rs b/core/src/renderer/null.rs index 36d73e2b54..a0c0a6b2cb 100644 --- a/core/src/renderer/null.rs +++ b/core/src/renderer/null.rs @@ -1,5 +1,5 @@ use crate::alignment; -use crate::image::{self, Image}; +use crate::image; use crate::renderer::{self, Renderer}; use crate::svg; use crate::text::{self, Text}; diff --git a/core/src/theme.rs b/core/src/theme.rs index 6b2c04da4f..50d72bdbc4 100644 --- a/core/src/theme.rs +++ b/core/src/theme.rs @@ -160,6 +160,7 @@ impl Theme { } } +#[allow(clippy::derivable_impls)] impl Default for Theme { fn default() -> Self { #[cfg(feature = "auto-detect-theme")] diff --git a/core/src/widget/text.rs b/core/src/widget/text.rs index d95095ba5d..8f6dd0a505 100644 --- a/core/src/widget/text.rs +++ b/core/src/widget/text.rs @@ -32,8 +32,6 @@ use crate::{ Widget, }; -use std::borrow::Cow; - pub use text::{LineHeight, Shaping, Wrapping}; /// A bunch of text. @@ -313,7 +311,7 @@ where } fn set_id(&mut self, id: crate::widget::Id) { - self.id = id + self.id = id; } } diff --git a/core/src/widget/tree.rs b/core/src/widget/tree.rs index af8ba86361..963a738137 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/graphics/src/image.rs b/graphics/src/image.rs index fcafb27aa0..ee2cb2df63 100644 --- a/graphics/src/image.rs +++ b/graphics/src/image.rs @@ -4,8 +4,6 @@ pub use ::image as image_rs; use crate::core::image; use crate::core::svg; -use crate::core::Color; -use crate::core::Radians; use crate::core::Rectangle; /// A raster or vector image. diff --git a/graphics/src/text/paragraph.rs b/graphics/src/text/paragraph.rs index f90282c637..21b35afa14 100644 --- a/graphics/src/text/paragraph.rs +++ b/graphics/src/text/paragraph.rs @@ -1,8 +1,8 @@ //! Draw paragraphs. use crate::core; use crate::core::alignment; -use crate::core::text::{Hit, LineHeight, Shaping, Span, Text, Wrapping}; -use crate::core::{Font, Pixels, Point, Rectangle, Size}; +use crate::core::text::{Hit, Shaping, Span, Text, Wrapping}; +use crate::core::{Font, Point, Rectangle, Size}; use crate::text; use std::fmt; diff --git a/renderer/src/fallback.rs b/renderer/src/fallback.rs index f940f15833..0bceaed065 100644 --- a/renderer/src/fallback.rs +++ b/renderer/src/fallback.rs @@ -3,7 +3,7 @@ use crate::core::image; use crate::core::renderer; use crate::core::svg; use crate::core::{ - self, Background, Color, Image, Point, Rectangle, Size, Svg, Transformation, + self, Background, Color, Point, Rectangle, Size, Svg, Transformation, }; use crate::graphics; use crate::graphics::compositor; diff --git a/runtime/src/dnd.rs b/runtime/src/dnd.rs index 0461becea8..69c956f686 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/application.rs b/src/application.rs index 17070afb02..2934eb9f3b 100644 --- a/src/application.rs +++ b/src/application.rs @@ -36,9 +36,7 @@ use crate::runtime::{Appearance, DefaultStyle}; #[cfg(feature = "winit")] pub use crate::shell::program::{Appearance, DefaultStyle}; use crate::window; -use crate::{ - Element, Executor, Font, Result, Settings, Size, Subscription, Task, -}; +use crate::{Element, Executor, Font, Settings, Size, Subscription, Task}; use std::borrow::Cow; diff --git a/src/daemon.rs b/src/daemon.rs index b672ca13cb..2990821756 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -4,7 +4,7 @@ use crate::program::{self, Program}; #[cfg(feature = "winit")] pub use crate::shell::program::{Appearance, DefaultStyle}; use crate::window; -use crate::{Element, Executor, Font, Result, Settings, Subscription, Task}; +use crate::{Element, Executor, Font, Settings, Subscription, Task}; #[cfg(not(feature = "winit"))] use crate::runtime::{Appearance, DefaultStyle}; diff --git a/src/lib.rs b/src/lib.rs index 9642cf11b1..0aedf2b358 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -663,7 +663,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 7e5b517a6c..9393d5525d 100644 --- a/tiny_skia/src/engine.rs +++ b/tiny_skia/src/engine.rs @@ -1,5 +1,3 @@ -use tiny_skia::Transform; - use crate::core::renderer::Quad; use crate::core::{ Background, Color, Gradient, Rectangle, Size, Transformation, Vector, @@ -565,6 +563,8 @@ impl Engine { match image { #[cfg(feature = "image")] Image::Raster { handle, bounds } => { + use tiny_skia::Transform; + let physical_bounds = *bounds * _transformation; if !_clip_bounds.intersects(&physical_bounds) { @@ -608,7 +608,7 @@ impl Engine { let center = physical_bounds.center(); let radians = f32::from(handle.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 30ee93bcad..3df644a2d3 100644 --- a/tiny_skia/src/layer.rs +++ b/tiny_skia/src/layer.rs @@ -1,6 +1,6 @@ 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; @@ -118,10 +118,10 @@ impl Layer { pub fn draw_image(&mut self, image: Image, transformation: Transformation) { match image { Image::Raster { handle, bounds } => { - self.draw_raster(handle, bounds, transformation) + self.draw_raster(handle, bounds, transformation); } Image::Vector { handle, bounds } => { - self.draw_svg(handle, bounds, transformation) + self.draw_svg(handle, bounds, transformation); } } } diff --git a/widget/src/button.rs b/widget/src/button.rs index 5d4e580a4e..12931f244f 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -288,7 +288,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 3956561cec..b36bd3dd3d 100644 --- a/widget/src/checkbox.rs +++ b/widget/src/checkbox.rs @@ -434,7 +434,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 9fe70d7c73..b693108084 100644 --- a/widget/src/container.rs +++ b/widget/src/container.rs @@ -579,7 +579,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 0eaddf5781..c125a06c1c 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -165,11 +165,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, } } @@ -346,7 +346,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, @@ -415,20 +415,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 event::Status::Captured; + { + 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 event::Status::Captured; } } diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index 8ae4b3cd90..56ab9709da 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -327,7 +327,7 @@ where ids, |state, (_, content)| content.diff(state), |(_, content)| content.state(), - ) + ); } Contents::Maximized(_, content, _) => tree.diff_children_custom( &mut [content], diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs index ff6ce9ea34..7e858a3a9f 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::event::{self, Event}; use crate::core::layout; diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs index 1495a575f2..54b6390bad 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::event::{self, Event}; use crate::core::layout; diff --git a/widget/src/row.rs b/widget/src/row.rs index 575dd24cd9..315243c370 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -204,7 +204,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 6841d19c80..cfa5985c98 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -456,7 +456,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 54eae1e08d..16bce89797 100644 --- a/widget/src/tooltip.rs +++ b/widget/src/tooltip.rs @@ -176,7 +176,7 @@ where tree.diff_children(&mut [ self.content.as_widget_mut(), self.tooltip.as_widget_mut(), - ]) + ]); } fn layout(