From c997aad85d7ee6e77085e50e5e599002549d228f Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 19 Sep 2023 01:46:46 -0400 Subject: Chore: Apply clippy map transformations Convert `.map().unwrap_or()` to `.map_or()` and similar transformations. --- core/src/mouse/click.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'core') diff --git a/core/src/mouse/click.rs b/core/src/mouse/click.rs index 4a7d796c..240e5c64 100644 --- a/core/src/mouse/click.rs +++ b/core/src/mouse/click.rs @@ -69,8 +69,6 @@ impl Click { }; self.position == new_position - && duration - .map(|duration| duration.as_millis() <= 300) - .unwrap_or(false) + && duration.is_some_and(|duration| duration.as_millis() <= 300) } } -- cgit From c6554d990770b941b5003d6ef40af3f9dedcd052 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 19 Sep 2023 01:50:05 -0400 Subject: Chore: Apply clippy docs keyword quoting Add quotes a number of doc strings like `sRGB` --- core/src/color.rs | 2 +- core/src/window/icon.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/src/color.rs b/core/src/color.rs index 1392f28b..0e8b7475 100644 --- a/core/src/color.rs +++ b/core/src/color.rs @@ -1,7 +1,7 @@ #[cfg(feature = "palette")] use palette::rgb::{Srgb, Srgba}; -/// A color in the sRGB color space. +/// A color in the `sRGB` color space. #[derive(Debug, Clone, Copy, PartialEq, Default)] pub struct Color { /// Red component, 0.0 - 1.0 diff --git a/core/src/window/icon.rs b/core/src/window/icon.rs index 2fc48e3b..5ef0eed7 100644 --- a/core/src/window/icon.rs +++ b/core/src/window/icon.rs @@ -3,7 +3,7 @@ use crate::Size; use std::mem; -/// Builds an [`Icon`] from its RGBA pixels in the sRGB color space. +/// Builds an [`Icon`] from its RGBA pixels in the `sRGB` color space. pub fn from_rgba( rgba: Vec, width: u32, -- cgit From efd0ff6ded4e647e5fad0964555dbed541a075d7 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Tue, 19 Sep 2023 01:52:25 -0400 Subject: Chore: Apply some minor clippy fixes * Use `.elapsed()` for duration * Use direct iteration without calling `.iter()` and the like * order fields in the `Text` struct creation as declared --- core/src/gradient.rs | 2 +- core/src/widget/text.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'core') diff --git a/core/src/gradient.rs b/core/src/gradient.rs index 4a0d5ea0..6a5533f8 100644 --- a/core/src/gradient.rs +++ b/core/src/gradient.rs @@ -94,7 +94,7 @@ impl Linear { mut self, stops: impl IntoIterator, ) -> Self { - for stop in stops.into_iter() { + for stop in stops { self = self.add_stop(stop.offset, stop.color) } diff --git a/core/src/widget/text.rs b/core/src/widget/text.rs index 53ed463e..ba98f2d8 100644 --- a/core/src/widget/text.rs +++ b/core/src/widget/text.rs @@ -220,9 +220,9 @@ where size, line_height, font, - shaping, horizontal_alignment, vertical_alignment, + shaping, }, ); -- cgit From 34f07b60273d6cfe13834af54cd0e24d34569387 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 04:11:52 +0200 Subject: Fix `clippy::semicolon_if_nothing_returned` --- core/src/element.rs | 6 +++--- core/src/gradient.rs | 2 +- core/src/hasher.rs | 2 +- core/src/overlay/element.rs | 6 +++--- core/src/overlay/group.rs | 2 +- core/src/shell.rs | 2 +- core/src/widget/operation/focusable.rs | 10 +++++----- core/src/widget/operation/scrollable.rs | 4 ++-- core/src/widget/operation/text_input.rs | 8 ++++---- core/src/widget/tree.rs | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) (limited to 'core') diff --git a/core/src/element.rs b/core/src/element.rs index 02f16bcb..dea111af 100644 --- a/core/src/element.rs +++ b/core/src/element.rs @@ -293,7 +293,7 @@ where } fn diff(&self, tree: &mut Tree) { - self.widget.diff(tree) + self.widget.diff(tree); } fn width(&self) -> Length { @@ -418,7 +418,7 @@ where viewport: &Rectangle, ) { self.widget - .draw(tree, renderer, theme, style, layout, cursor, viewport) + .draw(tree, renderer, theme, style, layout, cursor, viewport); } fn mouse_interaction( @@ -508,7 +508,7 @@ where ) { self.element .widget - .operate(state, layout, renderer, operation) + .operate(state, layout, renderer, operation); } fn on_event( diff --git a/core/src/gradient.rs b/core/src/gradient.rs index 6a5533f8..4711b044 100644 --- a/core/src/gradient.rs +++ b/core/src/gradient.rs @@ -95,7 +95,7 @@ impl Linear { stops: impl IntoIterator, ) -> Self { for stop in stops { - self = self.add_stop(stop.offset, stop.color) + self = self.add_stop(stop.offset, stop.color); } self diff --git a/core/src/hasher.rs b/core/src/hasher.rs index fa52f16d..9d8f75b3 100644 --- a/core/src/hasher.rs +++ b/core/src/hasher.rs @@ -4,7 +4,7 @@ pub struct Hasher(twox_hash::XxHash64); impl core::hash::Hasher for Hasher { fn write(&mut self, bytes: &[u8]) { - self.0.write(bytes) + self.0.write(bytes); } fn finish(&self) -> u64 { diff --git a/core/src/overlay/element.rs b/core/src/overlay/element.rs index 689e69be..3dd58f9b 100644 --- a/core/src/overlay/element.rs +++ b/core/src/overlay/element.rs @@ -98,7 +98,7 @@ where layout: Layout<'_>, cursor: mouse::Cursor, ) { - self.overlay.draw(renderer, theme, style, layout, cursor) + self.overlay.draw(renderer, theme, style, layout, cursor); } /// Applies a [`widget::Operation`] to the [`Element`]. @@ -205,7 +205,7 @@ where state: &mut dyn widget::operation::TextInput, id: Option<&widget::Id>, ) { - self.operation.text_input(state, id) + self.operation.text_input(state, id); } fn custom(&mut self, state: &mut dyn Any, id: Option<&widget::Id>) { @@ -262,7 +262,7 @@ where layout: Layout<'_>, cursor: mouse::Cursor, ) { - self.content.draw(renderer, theme, style, layout, cursor) + self.content.draw(renderer, theme, style, layout, cursor); } fn is_over( diff --git a/core/src/overlay/group.rs b/core/src/overlay/group.rs index a0bae6bb..dccf6dba 100644 --- a/core/src/overlay/group.rs +++ b/core/src/overlay/group.rs @@ -143,7 +143,7 @@ where |(child, layout)| { child.operate(layout, renderer, operation); }, - ) + ); }); } diff --git a/core/src/shell.rs b/core/src/shell.rs index 246c937a..2952ceff 100644 --- a/core/src/shell.rs +++ b/core/src/shell.rs @@ -71,7 +71,7 @@ impl<'a, Message> Shell<'a, Message> { if self.is_layout_invalid { self.is_layout_invalid = false; - f() + f(); } } diff --git a/core/src/widget/operation/focusable.rs b/core/src/widget/operation/focusable.rs index ab1b677e..68c22faa 100644 --- a/core/src/widget/operation/focusable.rs +++ b/core/src/widget/operation/focusable.rs @@ -49,7 +49,7 @@ pub fn focus(target: Id) -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } } @@ -85,7 +85,7 @@ where _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } fn finish(&self) -> Outcome { @@ -132,7 +132,7 @@ pub fn focus_previous() -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } } @@ -166,7 +166,7 @@ pub fn focus_next() -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } } @@ -193,7 +193,7 @@ pub fn find_focused() -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } fn finish(&self) -> Outcome { diff --git a/core/src/widget/operation/scrollable.rs b/core/src/widget/operation/scrollable.rs index 4f8b2a98..12161255 100644 --- a/core/src/widget/operation/scrollable.rs +++ b/core/src/widget/operation/scrollable.rs @@ -26,7 +26,7 @@ pub fn snap_to(target: Id, offset: RelativeOffset) -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } fn scrollable( @@ -60,7 +60,7 @@ pub fn scroll_to(target: Id, offset: AbsoluteOffset) -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } fn scrollable( diff --git a/core/src/widget/operation/text_input.rs b/core/src/widget/operation/text_input.rs index a9ea2e81..41731d4c 100644 --- a/core/src/widget/operation/text_input.rs +++ b/core/src/widget/operation/text_input.rs @@ -38,7 +38,7 @@ pub fn move_cursor_to_front(target: Id) -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } } @@ -68,7 +68,7 @@ pub fn move_cursor_to_end(target: Id) -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } } @@ -99,7 +99,7 @@ pub fn move_cursor_to(target: Id, position: usize) -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } } @@ -128,7 +128,7 @@ pub fn select_all(target: Id) -> impl Operation { _bounds: Rectangle, operate_on_children: &mut dyn FnMut(&mut dyn Operation), ) { - operate_on_children(self) + operate_on_children(self); } } diff --git a/core/src/widget/tree.rs b/core/src/widget/tree.rs index 202cca9a..d4b8828a 100644 --- a/core/src/widget/tree.rs +++ b/core/src/widget/tree.rs @@ -61,7 +61,7 @@ impl Tree { Renderer: crate::Renderer, { if self.tag == new.borrow().tag() { - new.borrow().diff(self) + new.borrow().diff(self); } else { *self = Self::new(new); } @@ -78,7 +78,7 @@ impl Tree { new_children, |tree, widget| tree.diff(widget.borrow()), |widget| Self::new(widget.borrow()), - ) + ); } /// Reconciliates the children of the tree with the provided list of widgets using custom -- cgit From 6c386e90a12fd26da12541da3f086dddb7211c0c Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 04:33:48 +0200 Subject: Fix `clippy::trivially-copy-pass-by-ref` --- core/src/mouse/click.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'core') diff --git a/core/src/mouse/click.rs b/core/src/mouse/click.rs index 240e5c64..53354098 100644 --- a/core/src/mouse/click.rs +++ b/core/src/mouse/click.rs @@ -24,7 +24,7 @@ pub enum Kind { } impl Kind { - fn next(&self) -> Kind { + fn next(self) -> Kind { match self { Kind::Single => Kind::Double, Kind::Double => Kind::Triple, -- cgit From b27762554627b8e89f2b840b1a8a512e22d4cd87 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 16:26:43 +0200 Subject: Revert "Chore: Apply clippy map transformations" This reverts commit c997aad85d7ee6e77085e50e5e599002549d228f. --- core/src/mouse/click.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/src/mouse/click.rs b/core/src/mouse/click.rs index 53354098..9cc44a71 100644 --- a/core/src/mouse/click.rs +++ b/core/src/mouse/click.rs @@ -69,6 +69,8 @@ impl Click { }; self.position == new_position - && duration.is_some_and(|duration| duration.as_millis() <= 300) + && duration + .map(|duration| duration.as_millis() <= 300) + .unwrap_or(false) } } -- cgit From f137d71e8fb926e784680d56d1cfa6817c3710a1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 20 Sep 2023 16:40:03 +0200 Subject: Centralize `clippy` lints in `.cargo/config.toml` --- core/src/lib.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'core') diff --git a/core/src/lib.rs b/core/src/lib.rs index 1bfba7bd..54ea5839 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -14,14 +14,8 @@ missing_debug_implementations, missing_docs, unused_results, - clippy::extra_unused_lifetimes, - clippy::from_over_into, - clippy::needless_borrow, - clippy::new_without_default, - clippy::useless_conversion, rustdoc::broken_intra_doc_links )] -#![allow(clippy::inherent_to_string, clippy::type_complexity)] pub mod alignment; pub mod clipboard; pub mod event; -- cgit