Enable and fix some more clippy lints

This commit is contained in:
Emil Ernerfeldt 2022-12-05 09:29:59 +01:00
parent e1f348e4b2
commit 5093b67e9b
28 changed files with 44 additions and 44 deletions

View file

@ -9,8 +9,10 @@ warn = [
"clippy::bool_to_int_with_if", "clippy::bool_to_int_with_if",
"clippy::char_lit_as_u8", "clippy::char_lit_as_u8",
"clippy::checked_conversions", "clippy::checked_conversions",
"clippy::cloned_instead_of_copied",
"clippy::dbg_macro", "clippy::dbg_macro",
"clippy::debug_assert_with_mut_call", "clippy::debug_assert_with_mut_call",
"clippy::derive_partial_eq_without_eq",
"clippy::disallowed_methods", "clippy::disallowed_methods",
"clippy::disallowed_script_idents", "clippy::disallowed_script_idents",
"clippy::doc_link_with_quotes", "clippy::doc_link_with_quotes",
@ -112,11 +114,9 @@ warn = [
allow = [ allow = [
# TODO(emilk): enable more lints # TODO(emilk): enable more lints
"clippy::cloned_instead_of_copied",
"clippy::derive_partial_eq_without_eq",
"clippy::type_complexity", "clippy::type_complexity",
"clippy::undocumented_unsafe_blocks", "clippy::undocumented_unsafe_blocks",
"trivial_casts", "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", "unused_qualifications",
] ]

View file

@ -230,7 +230,7 @@ impl Area {
let layer_id = LayerId::new(order, id); 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(); let is_new = state.is_none();
if is_new { if is_new {
ctx.request_repaint(); // if we don't know the previous size we are likely drawing the area in the wrong place ctx.request_repaint(); // if we don't know the previous size we are likely drawing the area in the wrong place

View file

@ -44,7 +44,7 @@ impl PanelState {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/// [`Left`](Side::Left) or [`Right`](Side::Right) /// [`Left`](Side::Left) or [`Right`](Side::Right)
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Side { pub enum Side {
Left, Left,
Right, Right,
@ -468,7 +468,7 @@ impl SidePanel {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/// [`Top`](TopBottomSide::Top) or [`Bottom`](TopBottomSide::Bottom) /// [`Top`](TopBottomSide::Top) or [`Bottom`](TopBottomSide::Bottom)
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TopBottomSide { pub enum TopBottomSide {
Top, Top,
Bottom, Bottom,

View file

@ -22,7 +22,7 @@ impl TooltipState {
fn individual_tooltip_size(&self, common_id: Id, index: usize) -> Option<Vec2> { fn individual_tooltip_size(&self, common_id: Id, index: usize) -> Option<Vec2> {
if self.last_common_id == Some(common_id) { 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 { } else {
None None
} }

View file

@ -1513,7 +1513,7 @@ impl Context {
ui.label("Hover to highlight"); ui.label("Hover to highlight");
let layers_ids: Vec<LayerId> = self.memory().areas.order().to_vec(); let layers_ids: Vec<LayerId> = self.memory().areas.order().to_vec();
for layer_id in layers_ids { 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 { if let Some(area) = area {
let is_visible = self.memory().areas.is_visible(&layer_id); let is_visible = self.memory().areas.is_visible(&layer_id);
if !is_visible { if !is_visible {

View file

@ -133,7 +133,7 @@ impl RawInput {
} }
/// A file about to be dropped into egui. /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct HoveredFile { pub struct HoveredFile {
/// Set by the `egui-winit` backend. /// Set by the `egui-winit` backend.
@ -144,7 +144,7 @@ pub struct HoveredFile {
} }
/// A file dropped into egui. /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct DroppedFile { pub struct DroppedFile {
/// Set by the `egui-winit` backend. /// 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 /// NOTE: For cross-platform uses, ALT+SHIFT is a bad combination of modifiers
/// as on mac that is how you type special characters, /// as on mac that is how you type special characters,
/// so those key presses are usually not reported to egui. /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Modifiers { pub struct Modifiers {
/// Either of the alt keys are down (option ⌥ on Mac). /// Either of the alt keys are down (option ⌥ on Mac).
@ -768,7 +768,7 @@ impl Key {
/// ///
/// Can be used with [`crate::InputState::consume_shortcut`] /// Can be used with [`crate::InputState::consume_shortcut`]
/// and [`crate::Context::format_shortcut`]. /// and [`crate::Context::format_shortcut`].
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct KeyboardShortcut { pub struct KeyboardShortcut {
pub modifiers: Modifiers, pub modifiers: Modifiers,
pub key: Key, pub key: Key,

View file

@ -156,7 +156,7 @@ impl PlatformOutput {
} }
/// What URL to open, and how. /// What URL to open, and how.
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct OpenUrl { pub struct OpenUrl {
pub url: String, pub url: String,
@ -190,7 +190,7 @@ impl OpenUrl {
/// egui emits a [`CursorIcon`] in [`PlatformOutput`] each frame as a request to the integration. /// egui emits a [`CursorIcon`] in [`PlatformOutput`] each frame as a request to the integration.
/// ///
/// Loosely based on <https://developer.mozilla.org/en-US/docs/Web/CSS/cursor>. /// Loosely based on <https://developer.mozilla.org/en-US/docs/Web/CSS/cursor>.
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum CursorIcon { pub enum CursorIcon {
/// Normal cursor icon, whatever that is. /// Normal cursor icon, whatever that is.

View file

@ -109,7 +109,7 @@ impl LayerId {
} }
/// A unique identifier of a specific [`Shape`] in a [`PaintList`]. /// A unique identifier of a specific [`Shape`] in a [`PaintList`].
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub struct ShapeIdx(usize); pub struct ShapeIdx(usize);
/// A list of [`Shape`]s paired with a clip rectangle. /// A list of [`Shape`]s paired with a clip rectangle.

View file

@ -75,7 +75,7 @@ impl Region {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/// Layout direction, one of [`LeftToRight`](Direction::LeftToRight), [`RightToLeft`](Direction::RightToLeft), [`TopDown`](Direction::TopDown), [`BottomUp`](Direction::BottomUp). /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum Direction { pub enum Direction {
LeftToRight, 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))] // #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Layout { pub struct Layout {
/// Main axis direction /// Main axis direction

View file

@ -507,7 +507,7 @@ pub mod special_emojis {
} }
/// The different types of built-in widgets in egui /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum WidgetType { pub enum WidgetType {
Label, // TODO(emilk): emit Label events Label, // TODO(emilk): emit Label events

View file

@ -587,8 +587,8 @@ impl Areas {
pub fn visible_layer_ids(&self) -> ahash::HashSet<LayerId> { pub fn visible_layer_ids(&self) -> ahash::HashSet<LayerId> {
self.visible_last_frame self.visible_last_frame
.iter() .iter()
.cloned() .copied()
.chain(self.visible_current_frame.iter().cloned()) .chain(self.visible_current_frame.iter().copied())
.collect() .collect()
} }

View file

@ -592,7 +592,7 @@ impl WidgetVisuals {
} }
/// Options for help debug egui by adding extra visualization /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct DebugOptions { pub struct DebugOptions {
/// However over widgets to see their rectangles /// However over widgets to see their rectangles

View file

@ -211,7 +211,7 @@ fn color_slider_2d(
} }
/// What options to show for alpha /// What options to show for alpha
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum Alpha { pub enum Alpha {
// Set alpha to 1.0, and show no option for it. // Set alpha to 1.0, and show no option for it.
Opaque, 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: // 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<Rgba>) -> Hsva { fn color_cache_get(ctx: &Context, rgba: impl Into<Rgba>) -> Hsva {
let rgba = rgba.into(); 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: // To ensure we keep hue slider when `srgba` is gray we store the full [`Hsva`] in a cache:

View file

@ -5,7 +5,7 @@ use crate::*;
use super::items::PlotItem; use super::items::PlotItem;
/// Where to place the plot legend. /// Where to place the plot legend.
#[derive(Debug, Clone, Copy, PartialEq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Corner { pub enum Corner {
LeftTop, LeftTop,
RightTop, RightTop,

View file

@ -76,7 +76,7 @@ pub fn drop_target<R>(
InnerResponse::new(ret, response) InnerResponse::new(ret, response)
} }
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct DragAndDropDemo { pub struct DragAndDropDemo {
/// columns with items /// columns with items

View file

@ -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", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))] #[cfg_attr(feature = "serde", serde(default))]
pub struct LayoutSettings { pub struct LayoutSettings {

View file

@ -1,5 +1,5 @@
/// Showcase [`TextEdit`]. /// Showcase [`TextEdit`].
#[derive(PartialEq)] #[derive(PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))] #[cfg_attr(feature = "serde", serde(default))]
pub struct TextEdit { pub struct TextEdit {

View file

@ -1,4 +1,4 @@
#[derive(Clone, PartialEq, Default)] #[derive(Clone, Default, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct WindowWithPanels {} pub struct WindowWithPanels {}

View file

@ -172,7 +172,7 @@ impl Rect {
/// Rotate the bounds (will expand the [`Rect`]) /// Rotate the bounds (will expand the [`Rect`])
#[must_use] #[must_use]
#[inline] #[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 a = rot * self.left_top().to_vec2();
let b = rot * self.right_top().to_vec2(); let b = rot * self.right_top().to_vec2();
let c = rot * self.left_bottom().to_vec2(); let c = rot * self.left_bottom().to_vec2();

View file

@ -1,10 +1,10 @@
use crate::*; use crate::{pos2, remap, remap_clamp, Pos2, Rect, Vec2};
/// Linearly transforms positions from one [`Rect`] to another. /// Linearly transforms positions from one [`Rect`] to another.
/// ///
/// [`RectTransform`] stores the rectangles, and therefore supports clamping and culling. /// [`RectTransform`] stores the rectangles, and therefore supports clamping and culling.
#[repr(C)] #[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 = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
pub struct RectTransform { pub struct RectTransform {

View file

@ -43,7 +43,7 @@ impl ImageData {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/// A 2D RGBA color image in RAM. /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct ColorImage { pub struct ColorImage {
/// width, height. /// width, height.

View file

@ -5,7 +5,7 @@ use emath::*;
/// ///
/// Should be friendly to send to GPU as is. /// Should be friendly to send to GPU as is.
#[repr(C)] #[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 = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
pub struct Vertex { pub struct Vertex {
@ -23,7 +23,7 @@ pub struct Vertex {
} }
/// Textured triangles in two dimensions. /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Mesh { pub struct Mesh {
/// Draw as triangles (i.e. the length is always multiple of three). /// Draw as triangles (i.e. the length is always multiple of three).

View file

@ -30,7 +30,7 @@ impl Shadow {
} }
} }
/// Used for widnows in dark mode. /// Used for egui windows in dark mode.
pub fn big_dark() -> Self { pub fn big_dark() -> Self {
Self { Self {
extrusion: 32.0, 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 { pub fn big_light() -> Self {
Self { Self {
extrusion: 32.0, extrusion: 32.0,
@ -46,7 +46,7 @@ impl Shadow {
} }
} }
pub fn tessellate(&self, rect: emath::Rect, rounding: impl Into<Rounding>) -> Mesh { pub fn tessellate(&self, rect: Rect, rounding: impl Into<Rounding>) -> Mesh {
// tessellator.clip_rect = clip_rect; // TODO(emilk): culling // tessellator.clip_rect = clip_rect; // TODO(emilk): culling
let Self { extrusion, color } = *self; let Self { extrusion, color } = *self;

View file

@ -586,7 +586,7 @@ pub mod path {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#[derive(Clone, Copy, PartialEq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum PathType { pub enum PathType {
Open, Open,
Closed, Closed,

View file

@ -66,7 +66,7 @@ impl std::ops::SubAssign<usize> for CCursor {
} }
/// Row Cursor /// Row Cursor
#[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 = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct RCursor { pub struct RCursor {
/// 0 is first row, and so on. /// 0 is first row, and so on.

View file

@ -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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct UvRect { pub struct UvRect {
/// X/Y offset for nice rendering (unit: points). /// X/Y offset for nice rendering (unit: points).

View file

@ -351,7 +351,7 @@ pub struct Galley {
pub pixels_per_point: f32, pub pixels_per_point: f32,
} }
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Row { pub struct Row {
/// One for each `char`. /// One for each `char`.
@ -374,7 +374,7 @@ pub struct Row {
} }
/// The tessellated output of a 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct RowVisuals { pub struct RowVisuals {
/// The tessellated text, using non-normalized (texel) UV coordinates. /// 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))] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Glyph { pub struct Glyph {
/// The character this glyph represents. /// The character this glyph represents.

View file

@ -117,7 +117,7 @@ impl TextureManager {
} }
/// Meta-data about an allocated texture. /// Meta-data about an allocated texture.
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct TextureMeta { pub struct TextureMeta {
/// A human-readable name useful for debugging. /// A human-readable name useful for debugging.
pub name: String, pub name: String,