From 22391b36fe247fc522bd2a1513832b9f935aa5df Mon Sep 17 00:00:00 2001 From: Daniel McNab <36049421+DJMcNab@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:59:38 +0100 Subject: [PATCH] Fix `clippy::use_self` --- Cargo.toml | 2 +- src/brush.rs | 8 ++++---- src/color.rs | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c02c5a3..cfb63f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,7 +88,7 @@ clippy.missing_errors_doc = "warn" clippy.missing_panics_doc = "warn" clippy.partial_pub_fields = "warn" clippy.shadow_unrelated = "warn" -# clippy.use_self = "warn" +clippy.use_self = "warn" # This catches duplicated dependencies in the tree, which we don't have much control over # We should use cargo deny for this, anyway diff --git a/src/brush.rs b/src/brush.rs index 9c9ba57..6e2273e 100644 --- a/src/brush.rs +++ b/src/brush.rs @@ -45,20 +45,20 @@ impl Brush { /// Returns the brush with the alpha component multiplied by the specified /// factor. #[must_use] - pub fn with_alpha_factor(self, alpha: f32) -> Brush { + pub fn with_alpha_factor(self, alpha: f32) -> Self { if alpha == 1.0 { self } else { match self { - Brush::Solid(color) => color.with_alpha_factor(alpha).into(), - Brush::Gradient(mut gradient) => { + Self::Solid(color) => color.with_alpha_factor(alpha).into(), + Self::Gradient(mut gradient) => { gradient .stops .iter_mut() .for_each(|stop| *stop = stop.with_alpha_factor(alpha)); gradient.into() } - Brush::Image(image) => image.with_alpha_factor(alpha).into(), + Self::Image(image) => image.with_alpha_factor(alpha).into(), } } } diff --git a/src/color.rs b/src/color.rs index 9559f52..09d6121 100644 --- a/src/color.rs +++ b/src/color.rs @@ -85,7 +85,7 @@ impl Color { #[allow(clippy::many_single_char_names)] #[allow(clippy::unreadable_literal)] #[must_use] - pub fn hlca(h: f64, l: f64, c: f64, alpha: f64) -> Color { + pub fn hlca(h: f64, l: f64, c: f64, alpha: f64) -> Self { // The reverse transformation from Lab to XYZ, see // https://en.wikipedia.org/wiki/CIELAB_color_space fn f_inv(t: f64) -> f64 { @@ -127,7 +127,7 @@ impl Color { 1.055 * u.powf(1. / 2.4) - 0.055 } } - Color::rgba(gamma(r_lin), gamma(g_lin), gamma(b_lin), alpha) + Self::rgba(gamma(r_lin), gamma(g_lin), gamma(b_lin), alpha) } /// Parses a color from a string. @@ -160,6 +160,7 @@ impl Color { } /// Named SVG colors. +#[allow(clippy::use_self)] impl Color { /// Alice blue (240, 248, 255, 255) pub const ALICE_BLUE: Color = Color::rgba8(240, 248, 255, 255);