From 5093b67e9b095072033e54557825f3bfc9d39c49 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 5 Dec 2022 09:29:59 +0100 Subject: [PATCH] Enable and fix some more clippy lints --- Cranky.toml | 6 +++--- crates/egui/src/containers/area.rs | 2 +- crates/egui/src/containers/panel.rs | 4 ++-- crates/egui/src/containers/popup.rs | 2 +- crates/egui/src/context.rs | 2 +- crates/egui/src/data/input.rs | 8 ++++---- crates/egui/src/data/output.rs | 4 ++-- crates/egui/src/layers.rs | 2 +- crates/egui/src/layout.rs | 4 ++-- crates/egui/src/lib.rs | 2 +- crates/egui/src/memory.rs | 4 ++-- crates/egui/src/style.rs | 2 +- crates/egui/src/widgets/color_picker.rs | 4 ++-- crates/egui/src/widgets/plot/legend.rs | 2 +- crates/egui_demo_lib/src/demo/drag_and_drop.rs | 2 +- crates/egui_demo_lib/src/demo/layout_test.rs | 2 +- crates/egui_demo_lib/src/demo/text_edit.rs | 2 +- crates/egui_demo_lib/src/demo/window_with_panels.rs | 2 +- crates/emath/src/rect.rs | 2 +- crates/emath/src/rect_transform.rs | 4 ++-- crates/epaint/src/image.rs | 2 +- crates/epaint/src/mesh.rs | 4 ++-- crates/epaint/src/shadow.rs | 6 +++--- crates/epaint/src/tessellator.rs | 2 +- crates/epaint/src/text/cursor.rs | 2 +- crates/epaint/src/text/font.rs | 2 +- crates/epaint/src/text/text_layout_types.rs | 6 +++--- crates/epaint/src/textures.rs | 2 +- 28 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Cranky.toml b/Cranky.toml index 28bb35fc..b2e0b313 100644 --- a/Cranky.toml +++ b/Cranky.toml @@ -9,8 +9,10 @@ warn = [ "clippy::bool_to_int_with_if", "clippy::char_lit_as_u8", "clippy::checked_conversions", + "clippy::cloned_instead_of_copied", "clippy::dbg_macro", "clippy::debug_assert_with_mut_call", + "clippy::derive_partial_eq_without_eq", "clippy::disallowed_methods", "clippy::disallowed_script_idents", "clippy::doc_link_with_quotes", @@ -112,11 +114,9 @@ warn = [ allow = [ # TODO(emilk): enable more lints - "clippy::cloned_instead_of_copied", - "clippy::derive_partial_eq_without_eq", "clippy::type_complexity", "clippy::undocumented_unsafe_blocks", "trivial_casts", - "unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668 + "unsafe_op_in_unsafe_fn", # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668 "unused_qualifications", ] diff --git a/crates/egui/src/containers/area.rs b/crates/egui/src/containers/area.rs index 072af44e..294d9efe 100644 --- a/crates/egui/src/containers/area.rs +++ b/crates/egui/src/containers/area.rs @@ -230,7 +230,7 @@ impl Area { let layer_id = LayerId::new(order, id); - let state = ctx.memory().areas.get(id).cloned(); + let state = ctx.memory().areas.get(id).copied(); let is_new = state.is_none(); if is_new { ctx.request_repaint(); // if we don't know the previous size we are likely drawing the area in the wrong place diff --git a/crates/egui/src/containers/panel.rs b/crates/egui/src/containers/panel.rs index a94f7b21..add3c035 100644 --- a/crates/egui/src/containers/panel.rs +++ b/crates/egui/src/containers/panel.rs @@ -44,7 +44,7 @@ impl PanelState { // ---------------------------------------------------------------------------- /// [`Left`](Side::Left) or [`Right`](Side::Right) -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Side { Left, Right, @@ -468,7 +468,7 @@ impl SidePanel { // ---------------------------------------------------------------------------- /// [`Top`](TopBottomSide::Top) or [`Bottom`](TopBottomSide::Bottom) -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum TopBottomSide { Top, Bottom, diff --git a/crates/egui/src/containers/popup.rs b/crates/egui/src/containers/popup.rs index 3ae49479..4decca3f 100644 --- a/crates/egui/src/containers/popup.rs +++ b/crates/egui/src/containers/popup.rs @@ -22,7 +22,7 @@ impl TooltipState { fn individual_tooltip_size(&self, common_id: Id, index: usize) -> Option { if self.last_common_id == Some(common_id) { - Some(self.individual_ids_and_sizes.get(&index).cloned()?.1) + Some(self.individual_ids_and_sizes.get(&index)?.1) } else { None } diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 12584d0d..a2127536 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -1513,7 +1513,7 @@ impl Context { ui.label("Hover to highlight"); let layers_ids: Vec = self.memory().areas.order().to_vec(); for layer_id in layers_ids { - let area = self.memory().areas.get(layer_id.id).cloned(); + let area = self.memory().areas.get(layer_id.id).copied(); if let Some(area) = area { let is_visible = self.memory().areas.is_visible(&layer_id); if !is_visible { diff --git a/crates/egui/src/data/input.rs b/crates/egui/src/data/input.rs index 0c079162..8cf23732 100644 --- a/crates/egui/src/data/input.rs +++ b/crates/egui/src/data/input.rs @@ -133,7 +133,7 @@ impl RawInput { } /// A file about to be dropped into egui. -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct HoveredFile { /// Set by the `egui-winit` backend. @@ -144,7 +144,7 @@ pub struct HoveredFile { } /// A file dropped into egui. -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct DroppedFile { /// Set by the `egui-winit` backend. @@ -305,7 +305,7 @@ pub const NUM_POINTER_BUTTONS: usize = 5; /// NOTE: For cross-platform uses, ALT+SHIFT is a bad combination of modifiers /// as on mac that is how you type special characters, /// so those key presses are usually not reported to egui. -#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Modifiers { /// Either of the alt keys are down (option ⌥ on Mac). @@ -768,7 +768,7 @@ impl Key { /// /// Can be used with [`crate::InputState::consume_shortcut`] /// and [`crate::Context::format_shortcut`]. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct KeyboardShortcut { pub modifiers: Modifiers, pub key: Key, diff --git a/crates/egui/src/data/output.rs b/crates/egui/src/data/output.rs index ffc51b08..a13307ef 100644 --- a/crates/egui/src/data/output.rs +++ b/crates/egui/src/data/output.rs @@ -156,7 +156,7 @@ impl PlatformOutput { } /// What URL to open, and how. -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct OpenUrl { pub url: String, @@ -190,7 +190,7 @@ impl OpenUrl { /// egui emits a [`CursorIcon`] in [`PlatformOutput`] each frame as a request to the integration. /// /// Loosely based on . -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum CursorIcon { /// Normal cursor icon, whatever that is. diff --git a/crates/egui/src/layers.rs b/crates/egui/src/layers.rs index f3b9674a..23e8b636 100644 --- a/crates/egui/src/layers.rs +++ b/crates/egui/src/layers.rs @@ -109,7 +109,7 @@ impl LayerId { } /// A unique identifier of a specific [`Shape`] in a [`PaintList`]. -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct ShapeIdx(usize); /// A list of [`Shape`]s paired with a clip rectangle. diff --git a/crates/egui/src/layout.rs b/crates/egui/src/layout.rs index 275c57b8..8da23700 100644 --- a/crates/egui/src/layout.rs +++ b/crates/egui/src/layout.rs @@ -75,7 +75,7 @@ impl Region { // ---------------------------------------------------------------------------- /// Layout direction, one of [`LeftToRight`](Direction::LeftToRight), [`RightToLeft`](Direction::RightToLeft), [`TopDown`](Direction::TopDown), [`BottomUp`](Direction::BottomUp). -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum Direction { LeftToRight, @@ -114,7 +114,7 @@ impl Direction { /// }); /// # }); /// ``` -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] // #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Layout { /// Main axis direction diff --git a/crates/egui/src/lib.rs b/crates/egui/src/lib.rs index 67aa46c6..c447ebaa 100644 --- a/crates/egui/src/lib.rs +++ b/crates/egui/src/lib.rs @@ -507,7 +507,7 @@ pub mod special_emojis { } /// The different types of built-in widgets in egui -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum WidgetType { Label, // TODO(emilk): emit Label events diff --git a/crates/egui/src/memory.rs b/crates/egui/src/memory.rs index a8ae6db6..f67ee8f9 100644 --- a/crates/egui/src/memory.rs +++ b/crates/egui/src/memory.rs @@ -587,8 +587,8 @@ impl Areas { pub fn visible_layer_ids(&self) -> ahash::HashSet { self.visible_last_frame .iter() - .cloned() - .chain(self.visible_current_frame.iter().cloned()) + .copied() + .chain(self.visible_current_frame.iter().copied()) .collect() } diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index a4cd8817..493b94ca 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -592,7 +592,7 @@ impl WidgetVisuals { } /// Options for help debug egui by adding extra visualization -#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct DebugOptions { /// However over widgets to see their rectangles diff --git a/crates/egui/src/widgets/color_picker.rs b/crates/egui/src/widgets/color_picker.rs index a9935f4d..37bbe217 100644 --- a/crates/egui/src/widgets/color_picker.rs +++ b/crates/egui/src/widgets/color_picker.rs @@ -211,7 +211,7 @@ fn color_slider_2d( } /// What options to show for alpha -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub enum Alpha { // Set alpha to 1.0, and show no option for it. Opaque, @@ -425,7 +425,7 @@ pub fn color_edit_button_rgb(ui: &mut Ui, rgb: &mut [f32; 3]) -> Response { // To ensure we keep hue slider when `srgba` is gray we store the full [`Hsva`] in a cache: fn color_cache_get(ctx: &Context, rgba: impl Into) -> Hsva { let rgba = rgba.into(); - use_color_cache(ctx, |cc| cc.get(&rgba).cloned()).unwrap_or_else(|| Hsva::from(rgba)) + use_color_cache(ctx, |cc| cc.get(&rgba).copied()).unwrap_or_else(|| Hsva::from(rgba)) } // To ensure we keep hue slider when `srgba` is gray we store the full [`Hsva`] in a cache: diff --git a/crates/egui/src/widgets/plot/legend.rs b/crates/egui/src/widgets/plot/legend.rs index 216f14b9..22ca3540 100644 --- a/crates/egui/src/widgets/plot/legend.rs +++ b/crates/egui/src/widgets/plot/legend.rs @@ -5,7 +5,7 @@ use crate::*; use super::items::PlotItem; /// Where to place the plot legend. -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Corner { LeftTop, RightTop, diff --git a/crates/egui_demo_lib/src/demo/drag_and_drop.rs b/crates/egui_demo_lib/src/demo/drag_and_drop.rs index 49bf62f4..89f662a5 100644 --- a/crates/egui_demo_lib/src/demo/drag_and_drop.rs +++ b/crates/egui_demo_lib/src/demo/drag_and_drop.rs @@ -76,7 +76,7 @@ pub fn drop_target( InnerResponse::new(ret, response) } -#[derive(Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct DragAndDropDemo { /// columns with items diff --git a/crates/egui_demo_lib/src/demo/layout_test.rs b/crates/egui_demo_lib/src/demo/layout_test.rs index 60193d9f..2d4fa8a8 100644 --- a/crates/egui_demo_lib/src/demo/layout_test.rs +++ b/crates/egui_demo_lib/src/demo/layout_test.rs @@ -21,7 +21,7 @@ impl Default for LayoutTest { } } -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] pub struct LayoutSettings { diff --git a/crates/egui_demo_lib/src/demo/text_edit.rs b/crates/egui_demo_lib/src/demo/text_edit.rs index c1aaa1f2..f23408a5 100644 --- a/crates/egui_demo_lib/src/demo/text_edit.rs +++ b/crates/egui_demo_lib/src/demo/text_edit.rs @@ -1,5 +1,5 @@ /// Showcase [`TextEdit`]. -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", serde(default))] pub struct TextEdit { diff --git a/crates/egui_demo_lib/src/demo/window_with_panels.rs b/crates/egui_demo_lib/src/demo/window_with_panels.rs index b8d1af5e..4d5f1140 100644 --- a/crates/egui_demo_lib/src/demo/window_with_panels.rs +++ b/crates/egui_demo_lib/src/demo/window_with_panels.rs @@ -1,4 +1,4 @@ -#[derive(Clone, PartialEq, Default)] +#[derive(Clone, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct WindowWithPanels {} diff --git a/crates/emath/src/rect.rs b/crates/emath/src/rect.rs index 887c09f1..6300bb11 100644 --- a/crates/emath/src/rect.rs +++ b/crates/emath/src/rect.rs @@ -172,7 +172,7 @@ impl Rect { /// Rotate the bounds (will expand the [`Rect`]) #[must_use] #[inline] - pub fn rotate_bb(self, rot: crate::Rot2) -> Self { + pub fn rotate_bb(self, rot: Rot2) -> Self { let a = rot * self.left_top().to_vec2(); let b = rot * self.right_top().to_vec2(); let c = rot * self.left_bottom().to_vec2(); diff --git a/crates/emath/src/rect_transform.rs b/crates/emath/src/rect_transform.rs index 9d700b99..de19fb67 100644 --- a/crates/emath/src/rect_transform.rs +++ b/crates/emath/src/rect_transform.rs @@ -1,10 +1,10 @@ -use crate::*; +use crate::{pos2, remap, remap_clamp, Pos2, Rect, Vec2}; /// Linearly transforms positions from one [`Rect`] to another. /// /// [`RectTransform`] stores the rectangles, and therefore supports clamping and culling. #[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] pub struct RectTransform { diff --git a/crates/epaint/src/image.rs b/crates/epaint/src/image.rs index 5fd4499b..dcd945aa 100644 --- a/crates/epaint/src/image.rs +++ b/crates/epaint/src/image.rs @@ -43,7 +43,7 @@ impl ImageData { // ---------------------------------------------------------------------------- /// A 2D RGBA color image in RAM. -#[derive(Clone, Default, PartialEq)] +#[derive(Clone, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct ColorImage { /// width, height. diff --git a/crates/epaint/src/mesh.rs b/crates/epaint/src/mesh.rs index d365a057..e9fc8334 100644 --- a/crates/epaint/src/mesh.rs +++ b/crates/epaint/src/mesh.rs @@ -5,7 +5,7 @@ use emath::*; /// /// Should be friendly to send to GPU as is. #[repr(C)] -#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] pub struct Vertex { @@ -23,7 +23,7 @@ pub struct Vertex { } /// Textured triangles in two dimensions. -#[derive(Clone, Debug, Default, PartialEq)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Mesh { /// Draw as triangles (i.e. the length is always multiple of three). diff --git a/crates/epaint/src/shadow.rs b/crates/epaint/src/shadow.rs index 953ff97c..22eccd5a 100644 --- a/crates/epaint/src/shadow.rs +++ b/crates/epaint/src/shadow.rs @@ -30,7 +30,7 @@ impl Shadow { } } - /// Used for widnows in dark mode. + /// Used for egui windows in dark mode. pub fn big_dark() -> Self { Self { extrusion: 32.0, @@ -38,7 +38,7 @@ impl Shadow { } } - /// Used for widnows in light mode. + /// Used for egui windows in light mode. pub fn big_light() -> Self { Self { extrusion: 32.0, @@ -46,7 +46,7 @@ impl Shadow { } } - pub fn tessellate(&self, rect: emath::Rect, rounding: impl Into) -> Mesh { + pub fn tessellate(&self, rect: Rect, rounding: impl Into) -> Mesh { // tessellator.clip_rect = clip_rect; // TODO(emilk): culling let Self { extrusion, color } = *self; diff --git a/crates/epaint/src/tessellator.rs b/crates/epaint/src/tessellator.rs index 7eb4089d..e6182ee6 100644 --- a/crates/epaint/src/tessellator.rs +++ b/crates/epaint/src/tessellator.rs @@ -586,7 +586,7 @@ pub mod path { // ---------------------------------------------------------------------------- -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq)] pub enum PathType { Open, Closed, diff --git a/crates/epaint/src/text/cursor.rs b/crates/epaint/src/text/cursor.rs index fcce2d47..2dac510d 100644 --- a/crates/epaint/src/text/cursor.rs +++ b/crates/epaint/src/text/cursor.rs @@ -66,7 +66,7 @@ impl std::ops::SubAssign for CCursor { } /// Row Cursor -#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct RCursor { /// 0 is first row, and so on. diff --git a/crates/epaint/src/text/font.rs b/crates/epaint/src/text/font.rs index e93356ab..4fb0079c 100644 --- a/crates/epaint/src/text/font.rs +++ b/crates/epaint/src/text/font.rs @@ -8,7 +8,7 @@ use std::sync::Arc; // ---------------------------------------------------------------------------- -#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct UvRect { /// X/Y offset for nice rendering (unit: points). diff --git a/crates/epaint/src/text/text_layout_types.rs b/crates/epaint/src/text/text_layout_types.rs index 12e0cf75..14ed82f3 100644 --- a/crates/epaint/src/text/text_layout_types.rs +++ b/crates/epaint/src/text/text_layout_types.rs @@ -351,7 +351,7 @@ pub struct Galley { pub pixels_per_point: f32, } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Row { /// One for each `char`. @@ -374,7 +374,7 @@ pub struct Row { } /// The tessellated output of a row. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct RowVisuals { /// The tessellated text, using non-normalized (texel) UV coordinates. @@ -400,7 +400,7 @@ impl Default for RowVisuals { } } -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Glyph { /// The character this glyph represents. diff --git a/crates/epaint/src/textures.rs b/crates/epaint/src/textures.rs index eec5ef26..ff466a6b 100644 --- a/crates/epaint/src/textures.rs +++ b/crates/epaint/src/textures.rs @@ -117,7 +117,7 @@ impl TextureManager { } /// Meta-data about an allocated texture. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct TextureMeta { /// A human-readable name useful for debugging. pub name: String,