From 9991052ce5617abf0f270bc9a74627ab6d45b35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 04:07:20 +0200 Subject: [PATCH 01/11] Create `cargo lint` alias --- .cargo/config.toml | 2 ++ .github/workflows/lint.yml | 2 +- .gitignore | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000000..088848882f --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +lint = "clippy --workspace --no-deps -- -D warnings -D clippy::semicolon_if_nothing_returned" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6fd98374c3..7fdc88679d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,4 +9,4 @@ jobs: components: clippy - uses: actions/checkout@master - name: Check lints - run: cargo clippy --workspace --all-features --all-targets --no-deps -- -D warnings + run: cargo lint diff --git a/.gitignore b/.gitignore index 0c46184fd1..f05ec438e4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,5 @@ target/ pkg/ **/*.rs.bk Cargo.lock -.cargo/ dist/ traces/ From 34f07b60273d6cfe13834af54cd0e24d34569387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 04:11:52 +0200 Subject: [PATCH 02/11] 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 ++-- examples/bezier_tool/src/main.rs | 2 +- examples/clock/src/main.rs | 2 +- examples/toast/src/main.rs | 2 +- examples/tooltip/src/main.rs | 2 +- examples/tour/src/main.rs | 2 +- graphics/src/geometry/path/builder.rs | 2 +- graphics/src/gradient.rs | 2 +- graphics/src/image.rs | 2 +- graphics/src/renderer.rs | 4 ++-- renderer/src/lib.rs | 4 ++-- runtime/src/overlay/nested.rs | 2 +- runtime/src/program/state.rs | 2 +- wgpu/src/buffer.rs | 2 +- wgpu/src/geometry.rs | 4 ++-- wgpu/src/image/atlas.rs | 2 +- wgpu/src/layer.rs | 2 +- widget/src/button.rs | 2 +- widget/src/column.rs | 2 +- widget/src/image.rs | 6 +++--- widget/src/image/viewer.rs | 2 +- widget/src/keyed/column.rs | 2 +- widget/src/lazy.rs | 6 +++--- widget/src/lazy/responsive.rs | 4 ++-- widget/src/pane_grid.rs | 4 ++-- widget/src/pane_grid/state.rs | 18 +++++++++--------- widget/src/pane_grid/title_bar.rs | 4 ++-- widget/src/pick_list.rs | 2 +- widget/src/row.rs | 4 ++-- widget/src/scrollable.rs | 10 +++++----- widget/src/slider.rs | 2 +- widget/src/text_input.rs | 24 ++++++++++++------------ widget/src/text_input/cursor.rs | 22 +++++++++++----------- widget/src/tooltip.rs | 2 +- widget/src/vertical_slider.rs | 2 +- winit/src/application.rs | 10 +++++----- winit/src/clipboard.rs | 4 ++-- 46 files changed, 108 insertions(+), 108 deletions(-) diff --git a/core/src/element.rs b/core/src/element.rs index 02f16bcba5..dea111afc7 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 6a5533f822..4711b04452 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 fa52f16d8a..9d8f75b38c 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 689e69be38..3dd58f9b58 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 a0bae6bbbc..dccf6dbaca 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 246c937a30..2952ceffae 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 ab1b677ea4..68c22faa8c 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 4f8b2a9819..121612550e 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 a9ea2e8137..41731d4c20 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 202cca9a50..d4b8828ae5 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 diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 310be28fc8..9e4bc49c11 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -81,7 +81,7 @@ mod bezier { } pub fn request_redraw(&mut self) { - self.cache.clear() + self.cache.clear(); } } diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs index fae77bc0f7..eec70ddeff 100644 --- a/examples/clock/src/main.rs +++ b/examples/clock/src/main.rs @@ -141,7 +141,7 @@ impl canvas::Program for Clock { frame.with_save(|frame| { frame.rotate(hand_rotation(self.now.second(), 60)); frame.stroke(&long_hand, thin_stroke()); - }) + }); }); vec![clock] diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs index 8570a38e6d..20c3dd4274 100644 --- a/examples/toast/src/main.rs +++ b/examples/toast/src/main.rs @@ -639,7 +639,7 @@ mod toast { child .as_widget() .operate(state, layout, renderer, operation); - }) + }); }); } diff --git a/examples/tooltip/src/main.rs b/examples/tooltip/src/main.rs index 35b862a832..a904cce07f 100644 --- a/examples/tooltip/src/main.rs +++ b/examples/tooltip/src/main.rs @@ -40,7 +40,7 @@ impl Sandbox for Example { Position::Right => Position::FollowCursor, }; - self.position = position + self.position = position; } } } diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 952300bb2d..d46e40d1e4 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -285,7 +285,7 @@ impl<'a> Step { is_showing_icon, .. } = self { - *is_showing_icon = toggle + *is_showing_icon = toggle; } } }; diff --git a/graphics/src/geometry/path/builder.rs b/graphics/src/geometry/path/builder.rs index 794dd3bcfa..b0959fbf89 100644 --- a/graphics/src/geometry/path/builder.rs +++ b/graphics/src/geometry/path/builder.rs @@ -174,7 +174,7 @@ impl Builder { /// the starting point. #[inline] pub fn close(&mut self) { - self.raw.close() + self.raw.close(); } /// Builds the [`Path`] of this [`Builder`]. diff --git a/graphics/src/gradient.rs b/graphics/src/gradient.rs index 7460e12e7b..603f1b4a67 100644 --- a/graphics/src/gradient.rs +++ b/graphics/src/gradient.rs @@ -88,7 +88,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/graphics/src/image.rs b/graphics/src/image.rs index 6b43f4a88f..d89caacecb 100644 --- a/graphics/src/image.rs +++ b/graphics/src/image.rs @@ -79,7 +79,7 @@ impl Operation { use image::imageops; if self.contains(Self::FLIP_DIAGONALLY) { - imageops::flip_vertical_in_place(&mut image) + imageops::flip_vertical_in_place(&mut image); } if self.contains(Self::ROTATE_180) { diff --git a/graphics/src/renderer.rs b/graphics/src/renderer.rs index d4df29a576..a9d7895eb6 100644 --- a/graphics/src/renderer.rs +++ b/graphics/src/renderer.rs @@ -237,7 +237,7 @@ where } fn draw(&mut self, handle: image::Handle, bounds: Rectangle) { - self.primitives.push(Primitive::Image { handle, bounds }) + self.primitives.push(Primitive::Image { handle, bounds }); } } @@ -259,6 +259,6 @@ where handle, color, bounds, - }) + }); } } diff --git a/renderer/src/lib.rs b/renderer/src/lib.rs index ef5c418268..8c76f52ef7 100644 --- a/renderer/src/lib.rs +++ b/renderer/src/lib.rs @@ -60,7 +60,7 @@ impl Renderer { pub fn draw_mesh(&mut self, mesh: Mesh) { match self { Self::TinySkia(_) => { - log::warn!("Unsupported mesh primitive: {mesh:?}") + log::warn!("Unsupported mesh primitive: {mesh:?}"); } #[cfg(feature = "wgpu")] Self::Wgpu(renderer) => { @@ -241,7 +241,7 @@ impl crate::core::svg::Renderer for Renderer { color: Option, bounds: Rectangle, ) { - delegate!(self, renderer, renderer.draw(handle, color, bounds)) + delegate!(self, renderer, renderer.draw(handle, color, bounds)); } } diff --git a/runtime/src/overlay/nested.rs b/runtime/src/overlay/nested.rs index 21b6f7c1e4..062ccc7290 100644 --- a/runtime/src/overlay/nested.rs +++ b/runtime/src/overlay/nested.rs @@ -164,7 +164,7 @@ where } } - recurse(&mut self.overlay, layout, renderer, operation) + recurse(&mut self.overlay, layout, renderer, operation); } /// Processes a runtime [`Event`]. diff --git a/runtime/src/program/state.rs b/runtime/src/program/state.rs index 9aa2d5507c..6f8f4063e2 100644 --- a/runtime/src/program/state.rs +++ b/runtime/src/program/state.rs @@ -200,7 +200,7 @@ where match operation.finish() { operation::Outcome::None => {} operation::Outcome::Some(message) => { - self.queued_messages.push(message) + self.queued_messages.push(message); } operation::Outcome::Chain(next) => { current_operation = Some(next); diff --git a/wgpu/src/buffer.rs b/wgpu/src/buffer.rs index 9412218729..ef00c58f4a 100644 --- a/wgpu/src/buffer.rs +++ b/wgpu/src/buffer.rs @@ -87,7 +87,7 @@ impl Buffer { /// Clears any temporary data (i.e. offsets) from the buffer. pub fn clear(&mut self) { - self.offsets.clear() + self.offsets.clear(); } /// Returns the offset at `index`, if it exists. diff --git a/wgpu/src/geometry.rs b/wgpu/src/geometry.rs index 63a59c05aa..655362b793 100644 --- a/wgpu/src/geometry.rs +++ b/wgpu/src/geometry.rs @@ -480,7 +480,7 @@ impl Frame { }, size: self.size, }), - )) + )); } } Buffer::Gradient(buffer) => { @@ -493,7 +493,7 @@ impl Frame { }, size: self.size, }), - )) + )); } } } diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index 1253496be4..e8ca4bd31a 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -104,7 +104,7 @@ impl Atlas { padded_data[offset..offset + 4 * width as usize].copy_from_slice( &data[row * 4 * width as usize..(row + 1) * 4 * width as usize], - ) + ); } match &entry { diff --git a/wgpu/src/layer.rs b/wgpu/src/layer.rs index 7a5a0f7ce3..d20dbe667c 100644 --- a/wgpu/src/layer.rs +++ b/wgpu/src/layer.rs @@ -202,7 +202,7 @@ impl<'a> Layer<'a> { translation, primitive, current_layer, - ) + ); } } Primitive::Clip { bounds, content } => { diff --git a/widget/src/button.rs b/widget/src/button.rs index 4915bd49e0..384a315643 100644 --- a/widget/src/button.rs +++ b/widget/src/button.rs @@ -146,7 +146,7 @@ where } fn diff(&self, tree: &mut Tree) { - tree.diff_children(std::slice::from_ref(&self.content)) + tree.diff_children(std::slice::from_ref(&self.content)); } fn width(&self) -> Length { diff --git a/widget/src/column.rs b/widget/src/column.rs index f2347cc99d..42e90ac105 100644 --- a/widget/src/column.rs +++ b/widget/src/column.rs @@ -159,7 +159,7 @@ where child .as_widget() .operate(state, layout, renderer, operation); - }) + }); }); } diff --git a/widget/src/image.rs b/widget/src/image.rs index 3c83c87bb2..a0e89920c7 100644 --- a/widget/src/image.rs +++ b/widget/src/image.rs @@ -141,14 +141,14 @@ pub fn draw( ..bounds }; - renderer.draw(handle.clone(), drawing_bounds + offset) + renderer.draw(handle.clone(), drawing_bounds + offset); }; if adjusted_fit.width > bounds.width || adjusted_fit.height > bounds.height { renderer.with_layer(bounds, render); } else { - render(renderer) + render(renderer); } } @@ -191,7 +191,7 @@ where _cursor: mouse::Cursor, _viewport: &Rectangle, ) { - draw(renderer, layout, &self.handle, self.content_fit) + draw(renderer, layout, &self.handle, self.content_fit); } } diff --git a/widget/src/image/viewer.rs b/widget/src/image/viewer.rs index 724d121e95..44624fc8ef 100644 --- a/widget/src/image/viewer.rs +++ b/widget/src/image/viewer.rs @@ -334,7 +334,7 @@ where y: bounds.y, ..Rectangle::with_size(image_size) }, - ) + ); }); }); } diff --git a/widget/src/keyed/column.rs b/widget/src/keyed/column.rs index 19016679f3..0ef82407cf 100644 --- a/widget/src/keyed/column.rs +++ b/widget/src/keyed/column.rs @@ -220,7 +220,7 @@ where child .as_widget() .operate(state, layout, renderer, operation); - }) + }); }); } diff --git a/widget/src/lazy.rs b/widget/src/lazy.rs index bf695a579f..589dd93807 100644 --- a/widget/src/lazy.rs +++ b/widget/src/lazy.rs @@ -135,7 +135,7 @@ where (*self.element.borrow_mut()) = Some(current.element.clone()); self.with_element(|element| { - tree.diff_children(std::slice::from_ref(&element.as_widget())) + tree.diff_children(std::slice::from_ref(&element.as_widget())); }); } else { (*self.element.borrow_mut()) = Some(current.element.clone()); @@ -243,8 +243,8 @@ where layout, cursor, viewport, - ) - }) + ); + }); } fn overlay<'b>( diff --git a/widget/src/lazy/responsive.rs b/widget/src/lazy/responsive.rs index 0b819455af..ed471988b4 100644 --- a/widget/src/lazy/responsive.rs +++ b/widget/src/lazy/responsive.rs @@ -240,9 +240,9 @@ where |tree, renderer, layout, element| { element.as_widget().draw( tree, renderer, theme, style, layout, cursor, viewport, - ) + ); }, - ) + ); } fn mouse_interaction( diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index f868a64812..3fb2597253 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -308,7 +308,7 @@ where .zip(layout.children()) .for_each(|(((_pane, content), state), layout)| { content.operate(state, layout, renderer, operation); - }) + }); }); } @@ -436,7 +436,7 @@ where tree, renderer, theme, style, layout, cursor, rectangle, ); }, - ) + ); } fn overlay<'b>( diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs index 28a52cf005..3721fa5507 100644 --- a/widget/src/pane_grid/state.rs +++ b/widget/src/pane_grid/state.rs @@ -156,16 +156,16 @@ impl State { Region::Center => self.swap(pane, target), Region::Edge(edge) => match edge { Edge::Top => { - self.split_and_swap(Axis::Horizontal, target, pane, true) + self.split_and_swap(Axis::Horizontal, target, pane, true); } Edge::Bottom => { - self.split_and_swap(Axis::Horizontal, target, pane, false) + self.split_and_swap(Axis::Horizontal, target, pane, false); } Edge::Left => { - self.split_and_swap(Axis::Vertical, target, pane, true) + self.split_and_swap(Axis::Vertical, target, pane, true); } Edge::Right => { - self.split_and_swap(Axis::Vertical, target, pane, false) + self.split_and_swap(Axis::Vertical, target, pane, false); } }, } @@ -176,7 +176,7 @@ impl State { match target { Target::Edge(edge) => self.move_to_edge(pane, edge), Target::Pane(target, region) => { - self.split_with(&target, pane, region) + self.split_with(&target, pane, region); } } } @@ -241,16 +241,16 @@ impl State { pub fn move_to_edge(&mut self, pane: &Pane, edge: Edge) { match edge { Edge::Top => { - self.split_major_node_and_swap(Axis::Horizontal, pane, true) + self.split_major_node_and_swap(Axis::Horizontal, pane, true); } Edge::Bottom => { - self.split_major_node_and_swap(Axis::Horizontal, pane, false) + self.split_major_node_and_swap(Axis::Horizontal, pane, false); } Edge::Left => { - self.split_major_node_and_swap(Axis::Vertical, pane, true) + self.split_major_node_and_swap(Axis::Vertical, pane, true); } Edge::Right => { - self.split_major_node_and_swap(Axis::Vertical, pane, false) + self.split_major_node_and_swap(Axis::Vertical, pane, false); } } } diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs index 5ae7a6a008..f4dbb6b145 100644 --- a/widget/src/pane_grid/title_bar.rs +++ b/widget/src/pane_grid/title_bar.rs @@ -286,7 +286,7 @@ where controls_layout, renderer, operation, - ) + ); }; if show_title { @@ -295,7 +295,7 @@ where title_layout, renderer, operation, - ) + ); } } diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index 056a5e65d0..fa0e3471f7 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -253,7 +253,7 @@ where &self.handle, &self.style, || tree.state.downcast_ref::>(), - ) + ); } fn overlay<'b>( diff --git a/widget/src/row.rs b/widget/src/row.rs index 71cf05097f..7ca90fbbe9 100644 --- a/widget/src/row.rs +++ b/widget/src/row.rs @@ -101,7 +101,7 @@ where } fn diff(&self, tree: &mut Tree) { - tree.diff_children(&self.children) + tree.diff_children(&self.children); } fn width(&self) -> Length { @@ -148,7 +148,7 @@ where child .as_widget() .operate(state, layout, renderer, operation); - }) + }); }); } diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index f92e622319..6f1e68fc51 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -217,7 +217,7 @@ where } fn diff(&self, tree: &mut Tree) { - tree.diff_children(std::slice::from_ref(&self.content)) + tree.diff_children(std::slice::from_ref(&self.content)); } fn width(&self) -> Length { @@ -348,9 +348,9 @@ where layout, cursor, viewport, - ) + ); }, - ) + ); } fn mouse_interaction( @@ -1069,7 +1069,7 @@ impl operation::Scrollable for State { } fn scroll_to(&mut self, offset: AbsoluteOffset) { - State::scroll_to(self, offset) + State::scroll_to(self, offset); } } @@ -1203,7 +1203,7 @@ impl State { (self.offset_y.absolute(bounds.height, content_bounds.height) - delta.y) .clamp(0.0, content_bounds.height - bounds.height), - ) + ); } if bounds.width < content_bounds.width { diff --git a/widget/src/slider.rs b/widget/src/slider.rs index 2c4a291394..ac0982c82f 100644 --- a/widget/src/slider.rs +++ b/widget/src/slider.rs @@ -223,7 +223,7 @@ where &self.range, theme, &self.style, - ) + ); } fn mouse_interaction( diff --git a/widget/src/text_input.rs b/widget/src/text_input.rs index 7d5ae8066f..9e1fb7964e 100644 --- a/widget/src/text_input.rs +++ b/widget/src/text_input.rs @@ -250,7 +250,7 @@ where self.is_secure, self.icon.as_ref(), &self.style, - ) + ); } } @@ -375,7 +375,7 @@ where self.is_secure, self.icon.as_ref(), &self.style, - ) + ); } fn mouse_interaction( @@ -622,7 +622,7 @@ where font, size, line_height, - ) + ); }; match event { @@ -849,7 +849,7 @@ where state.cursor.move_left_by_words(value); } } else if modifiers.shift() { - state.cursor.select_left(value) + state.cursor.select_left(value); } else { state.cursor.move_left(value); } @@ -864,7 +864,7 @@ where state.cursor.move_right_by_words(value); } } else if modifiers.shift() { - state.cursor.select_right(value) + state.cursor.select_right(value); } else { state.cursor.move_right(value); } @@ -1220,7 +1220,7 @@ pub fn draw( if text_width > text_bounds.width { renderer.with_layer(text_bounds, |renderer| { - renderer.with_translation(Vector::new(-offset, 0.0), render) + renderer.with_translation(Vector::new(-offset, 0.0), render); }); } else { render(renderer); @@ -1342,29 +1342,29 @@ impl operation::Focusable for State

{ } fn focus(&mut self) { - State::focus(self) + State::focus(self); } fn unfocus(&mut self) { - State::unfocus(self) + State::unfocus(self); } } impl operation::TextInput for State

{ fn move_cursor_to_front(&mut self) { - State::move_cursor_to_front(self) + State::move_cursor_to_front(self); } fn move_cursor_to_end(&mut self) { - State::move_cursor_to_end(self) + State::move_cursor_to_end(self); } fn move_cursor_to(&mut self, position: usize) { - State::move_cursor_to(self, position) + State::move_cursor_to(self, position); } fn select_all(&mut self) { - State::select_all(self) + State::select_all(self); } } diff --git a/widget/src/text_input/cursor.rs b/widget/src/text_input/cursor.rs index 9680dfd746..ea902485c3 100644 --- a/widget/src/text_input/cursor.rs +++ b/widget/src/text_input/cursor.rs @@ -65,11 +65,11 @@ impl Cursor { } pub(crate) fn move_right(&mut self, value: &Value) { - self.move_right_by_amount(value, 1) + self.move_right_by_amount(value, 1); } pub(crate) fn move_right_by_words(&mut self, value: &Value) { - self.move_to(value.next_end_of_word(self.right(value))) + self.move_to(value.next_end_of_word(self.right(value))); } pub(crate) fn move_right_by_amount( @@ -79,7 +79,7 @@ impl Cursor { ) { match self.state(value) { State::Index(index) => { - self.move_to(index.saturating_add(amount).min(value.len())) + self.move_to(index.saturating_add(amount).min(value.len())); } State::Selection { start, end } => self.move_to(end.max(start)), } @@ -108,10 +108,10 @@ impl Cursor { pub(crate) fn select_left(&mut self, value: &Value) { match self.state(value) { State::Index(index) if index > 0 => { - self.select_range(index, index - 1) + self.select_range(index, index - 1); } State::Selection { start, end } if end > 0 => { - self.select_range(start, end - 1) + self.select_range(start, end - 1); } _ => {} } @@ -120,10 +120,10 @@ impl Cursor { pub(crate) fn select_right(&mut self, value: &Value) { match self.state(value) { State::Index(index) if index < value.len() => { - self.select_range(index, index + 1) + self.select_range(index, index + 1); } State::Selection { start, end } if end < value.len() => { - self.select_range(start, end + 1) + self.select_range(start, end + 1); } _ => {} } @@ -132,10 +132,10 @@ impl Cursor { pub(crate) fn select_left_by_words(&mut self, value: &Value) { match self.state(value) { State::Index(index) => { - self.select_range(index, value.previous_start_of_word(index)) + self.select_range(index, value.previous_start_of_word(index)); } State::Selection { start, end } => { - self.select_range(start, value.previous_start_of_word(end)) + self.select_range(start, value.previous_start_of_word(end)); } } } @@ -143,10 +143,10 @@ impl Cursor { pub(crate) fn select_right_by_words(&mut self, value: &Value) { match self.state(value) { State::Index(index) => { - self.select_range(index, value.next_end_of_word(index)) + self.select_range(index, value.next_end_of_word(index)); } State::Selection { start, end } => { - self.select_range(start, value.next_end_of_word(end)) + self.select_range(start, value.next_end_of_word(end)); } } } diff --git a/widget/src/tooltip.rs b/widget/src/tooltip.rs index edc74e31bb..b041d2e943 100644 --- a/widget/src/tooltip.rs +++ b/widget/src/tooltip.rs @@ -114,7 +114,7 @@ where } fn diff(&self, tree: &mut widget::Tree) { - tree.diff_children(&[self.content.as_widget(), &self.tooltip]) + tree.diff_children(&[self.content.as_widget(), &self.tooltip]); } fn state(&self) -> widget::tree::State { diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs index 1efcd63b45..01d3359ca5 100644 --- a/widget/src/vertical_slider.rs +++ b/widget/src/vertical_slider.rs @@ -220,7 +220,7 @@ where &self.range, theme, &self.style, - ) + ); } fn mouse_interaction( diff --git a/winit/src/application.rs b/winit/src/application.rs index dec77e806c..8105f8d99d 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -762,7 +762,7 @@ pub fn run_command( size.width, size.height, ))) - .expect("Send message to event loop") + .expect("Send message to event loop"); } window::Action::Maximize(maximized) => { window.set_maximized(maximized); @@ -784,7 +784,7 @@ pub fn run_command( )); } window::Action::ChangeIcon(icon) => { - window.set_window_icon(conversion::icon(icon)) + window.set_window_icon(conversion::icon(icon)); } window::Action::FetchMode(tag) => { let mode = if window.is_visible().unwrap_or(true) { @@ -798,7 +798,7 @@ pub fn run_command( .expect("Send message to event loop"); } window::Action::ToggleMaximize => { - window.set_maximized(!window.is_maximized()) + window.set_maximized(!window.is_maximized()); } window::Action::ToggleDecorations => { window.set_decorations(!window.is_decorated()); @@ -833,7 +833,7 @@ pub fn run_command( bytes, state.physical_size(), ))) - .expect("Send message to event loop.") + .expect("Send message to event loop."); } }, command::Action::System(action) => match action { @@ -851,7 +851,7 @@ pub fn run_command( proxy .send_event(message) - .expect("Send message to event loop") + .expect("Send message to event loop"); }); } } diff --git a/winit/src/clipboard.rs b/winit/src/clipboard.rs index 4228e46f92..0a09c2555b 100644 --- a/winit/src/clipboard.rs +++ b/winit/src/clipboard.rs @@ -44,7 +44,7 @@ impl Clipboard { State::Connected(clipboard) => match clipboard.write(contents) { Ok(()) => {} Err(error) => { - log::warn!("error writing to clipboard: {error}") + log::warn!("error writing to clipboard: {error}"); } }, State::Unavailable => {} @@ -58,6 +58,6 @@ impl crate::core::Clipboard for Clipboard { } fn write(&mut self, contents: String) { - self.write(contents) + self.write(contents); } } From 6c386e90a12fd26da12541da3f086dddb7211c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 04:33:48 +0200 Subject: [PATCH 03/11] Fix `clippy::trivially-copy-pass-by-ref` --- .cargo/config.toml | 2 +- core/src/mouse/click.rs | 2 +- examples/pane_grid/src/main.rs | 29 +++++++----------- examples/todos/src/main.rs | 2 +- widget/src/pane_grid/node.rs | 14 ++++----- widget/src/pane_grid/state.rs | 54 +++++++++++++++++----------------- 6 files changed, 48 insertions(+), 55 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 088848882f..1e55e44795 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [alias] -lint = "clippy --workspace --no-deps -- -D warnings -D clippy::semicolon_if_nothing_returned" +lint = "clippy --workspace --no-deps -- -D warnings -D clippy::semicolon_if_nothing_returned -D clippy::trivially-copy-pass-by-ref" diff --git a/core/src/mouse/click.rs b/core/src/mouse/click.rs index 240e5c6464..5335409869 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, diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index af87e2c093..aa3149bbab 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -61,11 +61,8 @@ impl Application for Example { fn update(&mut self, message: Message) -> Command { match message { Message::Split(axis, pane) => { - let result = self.panes.split( - axis, - &pane, - Pane::new(self.panes_created), - ); + let result = + self.panes.split(axis, pane, Pane::new(self.panes_created)); if let Some((pane, _)) = result { self.focus = Some(pane); @@ -77,7 +74,7 @@ impl Application for Example { if let Some(pane) = self.focus { let result = self.panes.split( axis, - &pane, + pane, Pane::new(self.panes_created), ); @@ -90,8 +87,7 @@ impl Application for Example { } Message::FocusAdjacent(direction) => { if let Some(pane) = self.focus { - if let Some(adjacent) = - self.panes.adjacent(&pane, direction) + if let Some(adjacent) = self.panes.adjacent(pane, direction) { self.focus = Some(adjacent); } @@ -101,37 +97,34 @@ impl Application for Example { self.focus = Some(pane); } Message::Resized(pane_grid::ResizeEvent { split, ratio }) => { - self.panes.resize(&split, ratio); + self.panes.resize(split, ratio); } Message::Dragged(pane_grid::DragEvent::Dropped { pane, target, }) => { - self.panes.drop(&pane, target); + self.panes.drop(pane, target); } Message::Dragged(_) => {} Message::TogglePin(pane) => { - if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(&pane) - { + if let Some(Pane { is_pinned, .. }) = self.panes.get_mut(pane) { *is_pinned = !*is_pinned; } } - Message::Maximize(pane) => self.panes.maximize(&pane), + Message::Maximize(pane) => self.panes.maximize(pane), Message::Restore => { self.panes.restore(); } Message::Close(pane) => { - if let Some((_, sibling)) = self.panes.close(&pane) { + if let Some((_, sibling)) = self.panes.close(pane) { self.focus = Some(sibling); } } Message::CloseFocused => { if let Some(pane) = self.focus { - if let Some(Pane { is_pinned, .. }) = self.panes.get(&pane) - { + if let Some(Pane { is_pinned, .. }) = self.panes.get(pane) { if !is_pinned { - if let Some((_, sibling)) = self.panes.close(&pane) - { + if let Some((_, sibling)) = self.panes.close(pane) { self.focus = Some(sibling); } } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 3048a668ee..1ad3aba7f0 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -443,7 +443,7 @@ pub enum Filter { } impl Filter { - fn matches(&self, task: &Task) -> bool { + fn matches(self, task: &Task) -> bool { match self { Filter::All => true, Filter::Active => !task.completed, diff --git a/widget/src/pane_grid/node.rs b/widget/src/pane_grid/node.rs index 3c707f1584..1f568f95e5 100644 --- a/widget/src/pane_grid/node.rs +++ b/widget/src/pane_grid/node.rs @@ -95,13 +95,13 @@ impl Node { splits } - pub(crate) fn find(&mut self, pane: &Pane) -> Option<&mut Node> { + pub(crate) fn find(&mut self, pane: Pane) -> Option<&mut Node> { match self { Node::Split { a, b, .. } => { a.find(pane).or_else(move || b.find(pane)) } Node::Pane(p) => { - if p == pane { + if *p == pane { Some(self) } else { None @@ -139,12 +139,12 @@ impl Node { f(self); } - pub(crate) fn resize(&mut self, split: &Split, percentage: f32) -> bool { + pub(crate) fn resize(&mut self, split: Split, percentage: f32) -> bool { match self { Node::Split { id, ratio, a, b, .. } => { - if id == split { + if *id == split { *ratio = percentage; true @@ -158,13 +158,13 @@ impl Node { } } - pub(crate) fn remove(&mut self, pane: &Pane) -> Option { + pub(crate) fn remove(&mut self, pane: Pane) -> Option { match self { Node::Split { a, b, .. } => { - if a.pane() == Some(*pane) { + if a.pane() == Some(pane) { *self = *b.clone(); Some(self.first_pane()) - } else if b.pane() == Some(*pane) { + } else if b.pane() == Some(pane) { *self = *a.clone(); Some(self.first_pane()) } else { diff --git a/widget/src/pane_grid/state.rs b/widget/src/pane_grid/state.rs index 3721fa5507..481cd7709f 100644 --- a/widget/src/pane_grid/state.rs +++ b/widget/src/pane_grid/state.rs @@ -75,14 +75,14 @@ impl State { } /// Returns the internal state of the given [`Pane`], if it exists. - pub fn get(&self, pane: &Pane) -> Option<&T> { - self.panes.get(pane) + pub fn get(&self, pane: Pane) -> Option<&T> { + self.panes.get(&pane) } /// Returns the internal state of the given [`Pane`] with mutability, if it /// exists. - pub fn get_mut(&mut self, pane: &Pane) -> Option<&mut T> { - self.panes.get_mut(pane) + pub fn get_mut(&mut self, pane: Pane) -> Option<&mut T> { + self.panes.get_mut(&pane) } /// Returns an iterator over all the panes of the [`State`], alongside its @@ -104,13 +104,13 @@ impl State { /// Returns the adjacent [`Pane`] of another [`Pane`] in the given /// direction, if there is one. - pub fn adjacent(&self, pane: &Pane, direction: Direction) -> Option { + pub fn adjacent(&self, pane: Pane, direction: Direction) -> Option { let regions = self .internal .layout .pane_regions(0.0, Size::new(4096.0, 4096.0)); - let current_region = regions.get(pane)?; + let current_region = regions.get(&pane)?; let target = match direction { Direction::Left => { @@ -142,7 +142,7 @@ impl State { pub fn split( &mut self, axis: Axis, - pane: &Pane, + pane: Pane, state: T, ) -> Option<(Pane, Split)> { self.split_node(axis, Some(pane), state, false) @@ -151,7 +151,7 @@ impl State { /// Split a target [`Pane`] with a given [`Pane`] on a given [`Region`]. /// /// Panes will be swapped by default for [`Region::Center`]. - pub fn split_with(&mut self, target: &Pane, pane: &Pane, region: Region) { + pub fn split_with(&mut self, target: Pane, pane: Pane, region: Region) { match region { Region::Center => self.swap(pane, target), Region::Edge(edge) => match edge { @@ -172,11 +172,11 @@ impl State { } /// Drops the given [`Pane`] into the provided [`Target`]. - pub fn drop(&mut self, pane: &Pane, target: Target) { + pub fn drop(&mut self, pane: Pane, target: Target) { match target { Target::Edge(edge) => self.move_to_edge(pane, edge), Target::Pane(target, region) => { - self.split_with(&target, pane, region); + self.split_with(target, pane, region); } } } @@ -184,7 +184,7 @@ impl State { fn split_node( &mut self, axis: Axis, - pane: Option<&Pane>, + pane: Option, state: T, inverse: bool, ) -> Option<(Pane, Split)> { @@ -222,14 +222,14 @@ impl State { fn split_and_swap( &mut self, axis: Axis, - target: &Pane, - pane: &Pane, + target: Pane, + pane: Pane, swap: bool, ) { if let Some((state, _)) = self.close(pane) { if let Some((new_pane, _)) = self.split(axis, target, state) { if swap { - self.swap(target, &new_pane); + self.swap(target, new_pane); } } } @@ -238,7 +238,7 @@ impl State { /// Move [`Pane`] to an [`Edge`] of the [`PaneGrid`]. /// /// [`PaneGrid`]: super::PaneGrid - pub fn move_to_edge(&mut self, pane: &Pane, edge: Edge) { + pub fn move_to_edge(&mut self, pane: Pane, edge: Edge) { match edge { Edge::Top => { self.split_major_node_and_swap(Axis::Horizontal, pane, true); @@ -258,7 +258,7 @@ impl State { fn split_major_node_and_swap( &mut self, axis: Axis, - pane: &Pane, + pane: Pane, swap: bool, ) { if let Some((state, _)) = self.close(pane) { @@ -273,14 +273,14 @@ impl State { /// /// [`PaneGrid`]: super::PaneGrid /// [`DragEvent`]: super::DragEvent - pub fn swap(&mut self, a: &Pane, b: &Pane) { + pub fn swap(&mut self, a: Pane, b: Pane) { self.internal.layout.update(&|node| match node { Node::Split { .. } => {} Node::Pane(pane) => { - if pane == a { - *node = Node::Pane(*b); - } else if pane == b { - *node = Node::Pane(*a); + if *pane == a { + *node = Node::Pane(b); + } else if *pane == b { + *node = Node::Pane(a); } } }); @@ -296,19 +296,19 @@ impl State { /// /// [`PaneGrid`]: super::PaneGrid /// [`ResizeEvent`]: super::ResizeEvent - pub fn resize(&mut self, split: &Split, ratio: f32) { + pub fn resize(&mut self, split: Split, ratio: f32) { let _ = self.internal.layout.resize(split, ratio); } /// Closes the given [`Pane`] and returns its internal state and its closest /// sibling, if it exists. - pub fn close(&mut self, pane: &Pane) -> Option<(T, Pane)> { - if self.maximized == Some(*pane) { + pub fn close(&mut self, pane: Pane) -> Option<(T, Pane)> { + if self.maximized == Some(pane) { let _ = self.maximized.take(); } if let Some(sibling) = self.internal.layout.remove(pane) { - self.panes.remove(pane).map(|state| (state, sibling)) + self.panes.remove(&pane).map(|state| (state, sibling)) } else { None } @@ -318,8 +318,8 @@ impl State { /// [`PaneGrid`] until [`Self::restore()`] is called. /// /// [`PaneGrid`]: super::PaneGrid - pub fn maximize(&mut self, pane: &Pane) { - self.maximized = Some(*pane); + pub fn maximize(&mut self, pane: Pane) { + self.maximized = Some(pane); } /// Restore the currently maximized [`Pane`] to it's normal size. All panes From 42ed90bc6f92b2085d193e7f143430b8d3847c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 04:51:08 +0200 Subject: [PATCH 04/11] Fix `clippy::default_trait_access` --- .cargo/config.toml | 2 +- examples/arc/src/main.rs | 2 +- examples/clock/src/main.rs | 2 +- examples/integration/src/controls.rs | 2 +- examples/lazy/src/main.rs | 4 ++-- examples/modal/src/main.rs | 6 ++++-- examples/scrollable/src/main.rs | 4 ++-- examples/solar_system/src/main.rs | 4 ++-- renderer/src/geometry/cache.rs | 2 +- src/settings.rs | 4 ++-- src/window/settings.rs | 2 +- style/src/theme.rs | 6 +++--- tiny_skia/src/geometry.rs | 2 +- wgpu/src/color.rs | 6 +++--- wgpu/src/text.rs | 2 +- widget/src/pick_list.rs | 2 +- widget/src/scrollable.rs | 2 +- widget/src/toggler.rs | 2 +- winit/src/settings.rs | 2 +- 19 files changed, 30 insertions(+), 28 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 1e55e44795..f5c00d9b64 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [alias] -lint = "clippy --workspace --no-deps -- -D warnings -D clippy::semicolon_if_nothing_returned -D clippy::trivially-copy-pass-by-ref" +lint = "clippy --workspace --no-deps -- -D warnings -D clippy::semicolon_if_nothing_returned -D clippy::trivially-copy-pass-by-ref -D clippy::default_trait_access" diff --git a/examples/arc/src/main.rs b/examples/arc/src/main.rs index df56585931..6a68cca1f3 100644 --- a/examples/arc/src/main.rs +++ b/examples/arc/src/main.rs @@ -37,7 +37,7 @@ impl Application for Arc { ( Arc { start: Instant::now(), - cache: Default::default(), + cache: Cache::default(), }, Command::none(), ) diff --git a/examples/clock/src/main.rs b/examples/clock/src/main.rs index eec70ddeff..920aa0c583 100644 --- a/examples/clock/src/main.rs +++ b/examples/clock/src/main.rs @@ -35,7 +35,7 @@ impl Application for Clock { Clock { now: time::OffsetDateTime::now_local() .unwrap_or_else(|_| time::OffsetDateTime::now_utc()), - clock: Default::default(), + clock: Cache::default(), }, Command::none(), ) diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs index 14e53edeee..4714c397e7 100644 --- a/examples/integration/src/controls.rs +++ b/examples/integration/src/controls.rs @@ -19,7 +19,7 @@ impl Controls { pub fn new() -> Controls { Controls { background_color: Color::BLACK, - text: Default::default(), + text: String::default(), } } diff --git a/examples/lazy/src/main.rs b/examples/lazy/src/main.rs index c6baa6a136..9bf17c563a 100644 --- a/examples/lazy/src/main.rs +++ b/examples/lazy/src/main.rs @@ -27,7 +27,7 @@ impl Default for App { .into_iter() .map(From::from) .collect(), - input: Default::default(), + input: String::default(), order: Order::Ascending, } } @@ -107,7 +107,7 @@ impl From<&str> for Item { fn from(s: &str) -> Self { Self { name: s.to_owned(), - color: Default::default(), + color: Color::default(), } } } diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs index c050d3cc0a..b0e2c81b44 100644 --- a/examples/modal/src/main.rs +++ b/examples/modal/src/main.rs @@ -228,7 +228,9 @@ mod modal { use iced::alignment::Alignment; use iced::event; use iced::mouse; - use iced::{Color, Element, Event, Length, Point, Rectangle, Size}; + use iced::{ + BorderRadius, Color, Element, Event, Length, Point, Rectangle, Size, + }; /// A widget that centers a modal element over some base element pub struct Modal<'a, Message, Renderer> { @@ -474,7 +476,7 @@ mod modal { renderer.fill_quad( renderer::Quad { bounds: layout.bounds(), - border_radius: Default::default(), + border_radius: BorderRadius::default(), border_width: 0.0, border_color: Color::TRANSPARENT, }, diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs index 21e69284aa..d82ea84108 100644 --- a/examples/scrollable/src/main.rs +++ b/examples/scrollable/src/main.rs @@ -391,12 +391,12 @@ impl scrollable::StyleSheet for ScrollbarCustomStyle { .background, border_radius: 2.0.into(), border_width: 0.0, - border_color: Default::default(), + border_color: Color::default(), scroller: Scroller { color: Color::from_rgb8(250, 85, 134), border_radius: 2.0.into(), border_width: 0.0, - border_color: Default::default(), + border_color: Color::default(), }, } } else { diff --git a/examples/solar_system/src/main.rs b/examples/solar_system/src/main.rs index 8fa8946e86..8295ddeded 100644 --- a/examples/solar_system/src/main.rs +++ b/examples/solar_system/src/main.rs @@ -117,8 +117,8 @@ impl State { let (width, height) = window::Settings::default().size; State { - space_cache: Default::default(), - system_cache: Default::default(), + space_cache: canvas::Cache::default(), + system_cache: canvas::Cache::default(), start: now, now, stars: Self::generate_stars(width, height), diff --git a/renderer/src/geometry/cache.rs b/renderer/src/geometry/cache.rs index d82e7f6905..d4bb04b33e 100644 --- a/renderer/src/geometry/cache.rs +++ b/renderer/src/geometry/cache.rs @@ -35,7 +35,7 @@ impl Cache { /// Creates a new empty [`Cache`]. pub fn new() -> Self { Cache { - state: Default::default(), + state: RefCell::default(), } } diff --git a/src/settings.rs b/src/settings.rs index d9778d7e3b..c5e28e86b3 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -77,9 +77,9 @@ where fn default() -> Self { Self { id: None, - window: Default::default(), + window: window::Settings::default(), flags: Default::default(), - default_font: Default::default(), + default_font: Font::default(), default_text_size: Pixels(16.0), antialiasing: false, exit_on_close_request: true, diff --git a/src/window/settings.rs b/src/window/settings.rs index 458b9232c1..0ee573e563 100644 --- a/src/window/settings.rs +++ b/src/window/settings.rs @@ -52,7 +52,7 @@ impl Default for Settings { transparent: false, level: Level::default(), icon: None, - platform_specific: Default::default(), + platform_specific: PlatformSpecific::default(), } } } diff --git a/style/src/theme.rs b/style/src/theme.rs index 893d7202f2..3c1f2de62f 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -393,7 +393,7 @@ impl container::StyleSheet for Theme { fn appearance(&self, style: &Self::Style) -> container::Appearance { match style { - Container::Transparent => Default::default(), + Container::Transparent => container::Appearance::default(), Container::Box => { let palette = self.extended_palette(); @@ -904,7 +904,7 @@ impl svg::StyleSheet for Theme { fn appearance(&self, style: &Self::Style) -> svg::Appearance { match style { - Svg::Default => Default::default(), + Svg::Default => svg::Appearance::default(), Svg::Custom(custom) => custom.appearance(self), } } @@ -1053,7 +1053,7 @@ impl text::StyleSheet for Theme { fn appearance(&self, style: Self::Style) -> text::Appearance { match style { - Text::Default => Default::default(), + Text::Default => text::Appearance::default(), Text::Color(c) => text::Appearance { color: Some(c) }, } } diff --git a/tiny_skia/src/geometry.rs b/tiny_skia/src/geometry.rs index 1d573f6ac1..1d14aa037a 100644 --- a/tiny_skia/src/geometry.rs +++ b/tiny_skia/src/geometry.rs @@ -180,7 +180,7 @@ fn convert_path(path: &Path) -> Option { use iced_graphics::geometry::path::lyon_path; let mut builder = tiny_skia::PathBuilder::new(); - let mut last_point = Default::default(); + let mut last_point = lyon_path::math::Point::default(); for event in path.raw() { match event { diff --git a/wgpu/src/color.rs b/wgpu/src/color.rs index a1025601a2..20827e3c06 100644 --- a/wgpu/src/color.rs +++ b/wgpu/src/color.rs @@ -12,7 +12,7 @@ pub fn convert( let sampler = device.create_sampler(&wgpu::SamplerDescriptor { label: Some("iced_wgpu.offscreen.sampler"), - ..Default::default() + ..wgpu::SamplerDescriptor::default() }); //sampler in 0 @@ -102,10 +102,10 @@ pub fn convert( primitive: wgpu::PrimitiveState { topology: wgpu::PrimitiveTopology::TriangleList, front_face: wgpu::FrontFace::Cw, - ..Default::default() + ..wgpu::PrimitiveState::default() }, depth_stencil: None, - multisample: Default::default(), + multisample: wgpu::MultisampleState::default(), multiview: None, }); diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index bd4f3e067c..2a530cada8 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -64,7 +64,7 @@ impl Pipeline { self.renderers.push(glyphon::TextRenderer::new( &mut self.atlas, device, - Default::default(), + wgpu::MultisampleState::default(), None, )); } diff --git a/widget/src/pick_list.rs b/widget/src/pick_list.rs index fa0e3471f7..27f3290719 100644 --- a/widget/src/pick_list.rs +++ b/widget/src/pick_list.rs @@ -76,7 +76,7 @@ where text_line_height: text::LineHeight::default(), text_shaping: text::Shaping::Basic, font: None, - handle: Default::default(), + handle: Handle::default(), style: Default::default(), } } diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 6f1e68fc51..4cc9768457 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -46,7 +46,7 @@ where id: None, width: Length::Shrink, height: Length::Shrink, - direction: Default::default(), + direction: Direction::default(), content: content.into(), on_scroll: None, style: Default::default(), diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index 2440317fa8..476c8330c1 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -286,7 +286,7 @@ where style, label_layout, tree.state.downcast_ref(), - Default::default(), + crate::text::Appearance::default(), ); } diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 8d3e1b47fd..867dad0f2c 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -235,7 +235,7 @@ impl Default for Window { transparent: false, level: Level::default(), icon: None, - platform_specific: Default::default(), + platform_specific: PlatformSpecific::default(), } } } From caed50b277495e4375975f3f4e271b8fcbc0c33f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 05:03:25 +0200 Subject: [PATCH 05/11] Fix `clippy::match-wildcard-for-single-variants` --- .cargo/config.toml | 32 +++++++++++++++++++++++++- examples/download_progress/src/main.rs | 2 +- examples/game_of_life/src/main.rs | 4 ++-- renderer/src/lib.rs | 4 ++-- wgpu/src/image/atlas.rs | 2 +- widget/src/scrollable.rs | 4 ++-- widget/src/text_input/cursor.rs | 4 ++-- 7 files changed, 41 insertions(+), 11 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index f5c00d9b64..83564651e5 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,32 @@ [alias] -lint = "clippy --workspace --no-deps -- -D warnings -D clippy::semicolon_if_nothing_returned -D clippy::trivially-copy-pass-by-ref -D clippy::default_trait_access" +lint = """ +clippy --workspace --no-deps -- \ + -D warnings \ + -D clippy::semicolon_if_nothing_returned \ + -D clippy::trivially-copy-pass-by-ref \ + -D clippy::default_trait_access \ + -D clippy::match-wildcard-for-single-variants +""" + +nitpick = """ +clippy --workspace --no-deps -- \ + -D warnings \ + -D clippy::pedantic \ + -A clippy::must_use_candidate \ + -A clippy::return_self_not_must_use \ + -A clippy::needless_pass_by_value \ + -A clippy::cast_precision_loss \ + -A clippy::cast_sign_loss \ + -A clippy::cast_possible_truncation \ + -A clippy::match_same_arms \ + -A clippy::missing-errors-doc \ + -A clippy::missing-panics-doc \ + -A clippy::cast_lossless \ + -A clippy::doc_markdown \ + -A clippy::items_after_statements \ + -A clippy::too_many_lines \ + -A clippy::module_name_repetitions \ + -A clippy::if_not_else \ + -A clippy::redundant_else \ + -A clippy::used_underscore_binding +""" diff --git a/examples/download_progress/src/main.rs b/examples/download_progress/src/main.rs index 001a1f8fd4..e52c604cf2 100644 --- a/examples/download_progress/src/main.rs +++ b/examples/download_progress/src/main.rs @@ -123,7 +123,7 @@ impl Download { | State::Errored { .. } => { self.state = State::Downloading { progress: 0.0 }; } - _ => {} + State::Downloading{ .. } => {} } } diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index 437d89d5e4..c774e76968 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -472,7 +472,7 @@ mod grid { * (1.0 / self.scaling), )) } - _ => None, + Interaction::None => None, }; let event_status = match interaction { @@ -676,7 +676,7 @@ mod grid { Interaction::None if cursor.is_over(bounds) => { mouse::Interaction::Crosshair } - _ => mouse::Interaction::default(), + Interaction::None => mouse::Interaction::default(), } } } diff --git a/renderer/src/lib.rs b/renderer/src/lib.rs index 8c76f52ef7..1347ce04c7 100644 --- a/renderer/src/lib.rs +++ b/renderer/src/lib.rs @@ -257,7 +257,7 @@ impl crate::graphics::geometry::Renderer for Renderer { crate::Geometry::TinySkia(primitive) => { renderer.draw_primitive(primitive); } - _ => unreachable!(), + crate::Geometry::Wgpu(_) => unreachable!(), } } } @@ -268,7 +268,7 @@ impl crate::graphics::geometry::Renderer for Renderer { crate::Geometry::Wgpu(primitive) => { renderer.draw_primitive(primitive); } - _ => unreachable!(), + crate::Geometry::TinySkia(_) => unreachable!(), } } } diff --git a/wgpu/src/image/atlas.rs b/wgpu/src/image/atlas.rs index e8ca4bd31a..789e35b4d7 100644 --- a/wgpu/src/image/atlas.rs +++ b/wgpu/src/image/atlas.rs @@ -237,7 +237,7 @@ impl Atlas { })); } } - _ => {} + Layer::Full => {} } } diff --git a/widget/src/scrollable.rs b/widget/src/scrollable.rs index 4cc9768457..49aed2f0f9 100644 --- a/widget/src/scrollable.rs +++ b/widget/src/scrollable.rs @@ -117,7 +117,7 @@ impl Direction { match self { Self::Horizontal(properties) => Some(properties), Self::Both { horizontal, .. } => Some(horizontal), - _ => None, + Self::Vertical(_) => None, } } @@ -126,7 +126,7 @@ impl Direction { match self { Self::Vertical(properties) => Some(properties), Self::Both { vertical, .. } => Some(vertical), - _ => None, + Self::Horizontal(_) => None, } } } diff --git a/widget/src/text_input/cursor.rs b/widget/src/text_input/cursor.rs index ea902485c3..f682b17d68 100644 --- a/widget/src/text_input/cursor.rs +++ b/widget/src/text_input/cursor.rs @@ -56,7 +56,7 @@ impl Cursor { State::Selection { start, end } => { Some((start.min(end), start.max(end))) } - _ => None, + State::Index(_) => None, } } @@ -89,7 +89,7 @@ impl Cursor { match self.state(value) { State::Index(index) if index > 0 => self.move_to(index - 1), State::Selection { start, end } => self.move_to(start.min(end)), - _ => self.move_to(0), + State::Index(_) => self.move_to(0), } } From 1e4bade53aaaeb17542d0372ac827bcb7daf037c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 05:07:34 +0200 Subject: [PATCH 06/11] Fix `clippy::redundant-closure-for-method-calls` --- .cargo/config.toml | 6 ++++-- widget/src/lazy/component.rs | 2 +- winit/src/system.rs | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 83564651e5..61bfbf1758 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,7 +5,8 @@ clippy --workspace --no-deps -- \ -D clippy::semicolon_if_nothing_returned \ -D clippy::trivially-copy-pass-by-ref \ -D clippy::default_trait_access \ - -D clippy::match-wildcard-for-single-variants + -D clippy::match-wildcard-for-single-variants \ + -D clippy::redundant-closure-for-method-calls """ nitpick = """ @@ -28,5 +29,6 @@ clippy --workspace --no-deps -- \ -A clippy::module_name_repetitions \ -A clippy::if_not_else \ -A clippy::redundant_else \ - -A clippy::used_underscore_binding + -A clippy::used_underscore_binding \ + -A clippy::cast_possible_wrap """ diff --git a/widget/src/lazy/component.rs b/widget/src/lazy/component.rs index fe99a7f2cd..d454b72be6 100644 --- a/widget/src/lazy/component.rs +++ b/widget/src/lazy/component.rs @@ -511,7 +511,7 @@ impl<'a, 'b, Message, Renderer, Event, S> Drop for Overlay<'a, 'b, Message, Renderer, Event, S> { fn drop(&mut self) { - if let Some(heads) = self.0.take().map(|inner| inner.into_heads()) { + if let Some(heads) = self.0.take().map(Inner::into_heads) { *heads.instance.tree.borrow_mut().borrow_mut() = Some(heads.tree); } } diff --git a/winit/src/system.rs b/winit/src/system.rs index 145a4d92c1..d4cef60ef8 100644 --- a/winit/src/system.rs +++ b/winit/src/system.rs @@ -23,7 +23,7 @@ pub(crate) fn information( let memory_used = sysinfo::get_current_pid() .and_then(|pid| system.process(pid).ok_or("Process not found")) - .map(|process| process.memory()) + .map(ProcessExt::memory) .ok(); Information { From 14ba939e674ec4d9ca53b506ffa3259d30216e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 05:19:24 +0200 Subject: [PATCH 07/11] Fix `clippy::unreadable_literal` --- .cargo/config.toml | 9 +++++++-- tiny_skia/src/vector.rs | 6 +++--- wgpu/src/triangle.rs | 10 +++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 61bfbf1758..4ae09897f4 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -6,7 +6,7 @@ clippy --workspace --no-deps -- \ -D clippy::trivially-copy-pass-by-ref \ -D clippy::default_trait_access \ -D clippy::match-wildcard-for-single-variants \ - -D clippy::redundant-closure-for-method-calls + -D clippy::redundant-closure-for-method-calls \ """ nitpick = """ @@ -30,5 +30,10 @@ clippy --workspace --no-deps -- \ -A clippy::if_not_else \ -A clippy::redundant_else \ -A clippy::used_underscore_binding \ - -A clippy::cast_possible_wrap + -A clippy::cast_possible_wrap \ + -A clippy::unnecessary_wraps \ + -A clippy::struct-excessive-bools \ + -A clippy::float-cmp \ + -A clippy::single_match_else \ + -A clippy::unreadable_literal """ diff --git a/tiny_skia/src/vector.rs b/tiny_skia/src/vector.rs index 490b9f6908..a1cd269d98 100644 --- a/tiny_skia/src/vector.rs +++ b/tiny_skia/src/vector.rs @@ -172,9 +172,9 @@ impl Cache { for pixel in bytemuck::cast_slice_mut::(image.data_mut()) { - *pixel = *pixel & 0xFF00FF00 - | ((0x000000FF & *pixel) << 16) - | ((0x00FF0000 & *pixel) >> 16); + *pixel = *pixel & 0xFF00_FF00 + | ((0x0000_00FF & *pixel) << 16) + | ((0x00FF_0000 & *pixel) >> 16); } } diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs index 7e1bd9cccf..f8014cebd7 100644 --- a/wgpu/src/triangle.rs +++ b/wgpu/src/triangle.rs @@ -329,12 +329,12 @@ impl Pipeline { fn fragment_target( texture_format: wgpu::TextureFormat, -) -> Option { - Some(wgpu::ColorTargetState { +) -> wgpu::ColorTargetState { + wgpu::ColorTargetState { format: texture_format, blend: Some(wgpu::BlendState::ALPHA_BLENDING), write_mask: wgpu::ColorWrites::ALL, - }) + } } fn primitive_state() -> wgpu::PrimitiveState { @@ -521,7 +521,7 @@ mod solid { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "solid_fs_main", - targets: &[triangle::fragment_target(format)], + targets: &[Some(triangle::fragment_target(format))], }), primitive: triangle::primitive_state(), depth_stencil: None, @@ -698,7 +698,7 @@ mod gradient { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "gradient_fs_main", - targets: &[triangle::fragment_target(format)], + targets: &[Some(triangle::fragment_target(format))], }), primitive: triangle::primitive_state(), depth_stencil: None, From 1019d1e518d8ffe760142ccd5ff33d077434c8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 05:23:15 +0200 Subject: [PATCH 08/11] Fix `clippy::filter_map_next` --- .cargo/config.toml | 5 ++++- widget/src/pane_grid.rs | 25 +++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 4ae09897f4..d49e034f9f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,6 +7,7 @@ clippy --workspace --no-deps -- \ -D clippy::default_trait_access \ -D clippy::match-wildcard-for-single-variants \ -D clippy::redundant-closure-for-method-calls \ + -D clippy::filter_map_next """ nitpick = """ @@ -35,5 +36,7 @@ clippy --workspace --no-deps -- \ -A clippy::struct-excessive-bools \ -A clippy::float-cmp \ -A clippy::single_match_else \ - -A clippy::unreadable_literal + -A clippy::unreadable_literal \ + -A clippy::explicit_deref_methods \ + -A clippy::map_unwrap_or """ diff --git a/widget/src/pane_grid.rs b/widget/src/pane_grid.rs index 3fb2597253..2d25a543ee 100644 --- a/widget/src/pane_grid.rs +++ b/widget/src/pane_grid.rs @@ -606,11 +606,10 @@ pub fn update<'a, Message, T: Draggable>( } else { let dropped_region = contents .zip(layout.children()) - .filter_map(|(target, layout)| { + .find_map(|(target, layout)| { layout_region(layout, cursor_position) .map(|region| (target, region)) - }) - .next(); + }); match dropped_region { Some(((target, _), region)) @@ -1151,21 +1150,19 @@ pub struct ResizeEvent { * Helpers */ fn hovered_split<'a>( - splits: impl Iterator, + mut splits: impl Iterator, spacing: f32, cursor_position: Point, ) -> Option<(Split, Axis, Rectangle)> { - splits - .filter_map(|(split, (axis, region, ratio))| { - let bounds = axis.split_line_bounds(*region, *ratio, spacing); + splits.find_map(|(split, (axis, region, ratio))| { + let bounds = axis.split_line_bounds(*region, *ratio, spacing); - if bounds.contains(cursor_position) { - Some((*split, *axis, bounds)) - } else { - None - } - }) - .next() + if bounds.contains(cursor_position) { + Some((*split, *axis, bounds)) + } else { + None + } + }) } /// The visible contents of the [`PaneGrid`] From f8f1a8634402a5eb4275ff0814d03a3104fea65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 05:30:08 +0200 Subject: [PATCH 09/11] Fix `clippy::manual_let_else` --- .cargo/config.toml | 8 ++++++-- examples/bezier_tool/src/main.rs | 9 +++------ examples/game_of_life/src/main.rs | 9 +++------ examples/integration/src/main.rs | 2 +- examples/integration/src/scene.rs | 1 - examples/sierpinski_triangle/src/main.rs | 5 +---- examples/websocket/src/echo/server.rs | 5 +---- 7 files changed, 15 insertions(+), 24 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index d49e034f9f..2c6b20b64f 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -7,7 +7,8 @@ clippy --workspace --no-deps -- \ -D clippy::default_trait_access \ -D clippy::match-wildcard-for-single-variants \ -D clippy::redundant-closure-for-method-calls \ - -D clippy::filter_map_next + -D clippy::filter_map_next \ + -D clippy::manual_let_else """ nitpick = """ @@ -38,5 +39,8 @@ clippy --workspace --no-deps -- \ -A clippy::single_match_else \ -A clippy::unreadable_literal \ -A clippy::explicit_deref_methods \ - -A clippy::map_unwrap_or + -A clippy::map_unwrap_or \ + -A clippy::unnested_or_patterns \ + -A clippy::similar_names \ + -A clippy::unused_self """ diff --git a/examples/bezier_tool/src/main.rs b/examples/bezier_tool/src/main.rs index 9e4bc49c11..56cb23ba8b 100644 --- a/examples/bezier_tool/src/main.rs +++ b/examples/bezier_tool/src/main.rs @@ -100,12 +100,9 @@ mod bezier { bounds: Rectangle, cursor: mouse::Cursor, ) -> (event::Status, Option) { - let cursor_position = - if let Some(position) = cursor.position_in(bounds) { - position - } else { - return (event::Status::Ignored, None); - }; + let Some(cursor_position) = cursor.position_in(bounds) else { + return (event::Status::Ignored, None); + }; match event { Event::Mouse(mouse_event) => { diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs index c774e76968..96840143af 100644 --- a/examples/game_of_life/src/main.rs +++ b/examples/game_of_life/src/main.rs @@ -406,12 +406,9 @@ mod grid { *interaction = Interaction::None; } - let cursor_position = - if let Some(position) = cursor.position_in(bounds) { - position - } else { - return (event::Status::Ignored, None); - }; + let Some(cursor_position) = cursor.position_in(bounds) else { + return (event::Status::Ignored, None); + }; let cell = Cell::at(self.project(cursor_position, bounds.size())); let is_populated = self.state.contains(&cell); diff --git a/examples/integration/src/main.rs b/examples/integration/src/main.rs index 243297b23d..4415fefa0b 100644 --- a/examples/integration/src/main.rs +++ b/examples/integration/src/main.rs @@ -256,7 +256,7 @@ pub fn main() -> Result<(), Box> { { // We clear the frame - let mut render_pass = scene.clear( + let mut render_pass = Scene::clear( &view, &mut encoder, program.background_color(), diff --git a/examples/integration/src/scene.rs b/examples/integration/src/scene.rs index 90c7efbfa7..01808f40ed 100644 --- a/examples/integration/src/scene.rs +++ b/examples/integration/src/scene.rs @@ -16,7 +16,6 @@ impl Scene { } pub fn clear<'a>( - &self, target: &'a wgpu::TextureView, encoder: &'a mut wgpu::CommandEncoder, background_color: Color, diff --git a/examples/sierpinski_triangle/src/main.rs b/examples/sierpinski_triangle/src/main.rs index 885d3c635a..ef935c3342 100644 --- a/examples/sierpinski_triangle/src/main.rs +++ b/examples/sierpinski_triangle/src/main.rs @@ -108,10 +108,7 @@ impl canvas::Program for SierpinskiGraph { bounds: Rectangle, cursor: mouse::Cursor, ) -> (event::Status, Option) { - let cursor_position = if let Some(position) = cursor.position_in(bounds) - { - position - } else { + let Some(cursor_position) = cursor.position_in(bounds) else { return (event::Status::Ignored, None); }; diff --git a/examples/websocket/src/echo/server.rs b/examples/websocket/src/echo/server.rs index 168a635e01..a696a7a45c 100644 --- a/examples/websocket/src/echo/server.rs +++ b/examples/websocket/src/echo/server.rs @@ -47,10 +47,7 @@ async fn user_connected(ws: WebSocket) { }); while let Some(result) = user_ws_rx.next().await { - let msg = match result { - Ok(msg) => msg, - Err(_) => break, - }; + let Ok(msg) = result else { break }; let _ = tx.send(msg).await; } From 432d9f5f97a7312878f2f86ead13b6742638f7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 05:36:11 +0200 Subject: [PATCH 10/11] Fix `clippy::unused_async` --- .cargo/config.toml | 3 ++- examples/screenshot/Cargo.toml | 8 ++++++-- examples/screenshot/src/main.rs | 23 ++++++++++++++--------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 2c6b20b64f..9e265aa961 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -8,7 +8,8 @@ clippy --workspace --no-deps -- \ -D clippy::match-wildcard-for-single-variants \ -D clippy::redundant-closure-for-method-calls \ -D clippy::filter_map_next \ - -D clippy::manual_let_else + -D clippy::manual_let_else \ + -D clippy::unused_async """ nitpick = """ diff --git a/examples/screenshot/Cargo.toml b/examples/screenshot/Cargo.toml index dcd7743981..77b108bd51 100644 --- a/examples/screenshot/Cargo.toml +++ b/examples/screenshot/Cargo.toml @@ -7,7 +7,11 @@ publish = false [dependencies] iced.workspace = true -iced.features = ["debug", "image", "advanced"] +iced.features = ["debug", "image", "advanced", "tokio"] + +image.workspace = true +image.features = ["png"] + +tokio.workspace = true -image = { workspace = true, features = ["png"]} tracing-subscriber = "0.3" \ No newline at end of file diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs index d9784dc8f4..fa06d3e900 100644 --- a/examples/screenshot/src/main.rs +++ b/examples/screenshot/src/main.rs @@ -273,15 +273,20 @@ impl Application for Example { async fn save_to_png(screenshot: Screenshot) -> Result { let path = "screenshot.png".to_string(); - img::save_buffer( - &path, - &screenshot.bytes, - screenshot.size.width, - screenshot.size.height, - ColorType::Rgba8, - ) - .map(|_| path) - .map_err(|err| PngError(format!("{err:?}"))) + + tokio::task::spawn_blocking(move || { + img::save_buffer( + &path, + &screenshot.bytes, + screenshot.size.width, + screenshot.size.height, + ColorType::Rgba8, + ) + .map(|_| path) + .map_err(|err| PngError(format!("{err:?}"))) + }) + .await + .expect("Blocking task to finish") } #[derive(Clone, Debug)] From 33d780f691829ecd32f3a218008fcb40e005deb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Wed, 20 Sep 2023 05:37:20 +0200 Subject: [PATCH 11/11] Run `cargo fmt` --- examples/download_progress/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/download_progress/src/main.rs b/examples/download_progress/src/main.rs index e52c604cf2..a2fcb2753b 100644 --- a/examples/download_progress/src/main.rs +++ b/examples/download_progress/src/main.rs @@ -123,7 +123,7 @@ impl Download { | State::Errored { .. } => { self.state = State::Downloading { progress: 0.0 }; } - State::Downloading{ .. } => {} + State::Downloading { .. } => {} } }