Skip to content

Commit

Permalink
Require clippy lints to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogeon committed Sep 1, 2023
1 parent 4c29b26 commit aae68da
Show file tree
Hide file tree
Showing 45 changed files with 158 additions and 149 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.60.0
with:
components: clippy
- name: Minimal check
run: cargo check -v -p palette --no-default-features --features std
run: cargo clippy -v -p palette --no-default-features --features std
- name: find-crate check
run: cargo check -v -p palette --no-default-features --features "std find-crate"
run: cargo clippy -v -p palette --no-default-features --features "std find-crate"
- name: Default check
run: cargo check -v --workspace --exclude no_std_test
run: cargo clippy -v --workspace --exclude no_std_test
- name: Test all features
run: cargo test -v -p palette --all-features
- name: Test each feature
Expand All @@ -47,8 +49,9 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain }}
components: clippy
- name: Check all features
run: cargo check -v -p palette --all-features
run: cargo clippy -v -p palette --all-features
no_std:
name: "Test #[no_std]"
runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
],
"rust-analyzer.imports.granularity.enforce": true,
"rust-analyzer.imports.granularity.group": "crate",
"rust-analyzer.imports.group.enable": true
}
"rust-analyzer.imports.group.enable": true,
"rust-analyzer.check.command": "clippy"
}
1 change: 1 addition & 0 deletions palette/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ edition = "2018"
resolver = "2"
categories = ["graphics", "multimedia::images", "no-std"]
build = "build/main.rs"
rust-version = "1.60.0"

[features]
default = ["named_from_str", "std", "approx"]
Expand Down
2 changes: 1 addition & 1 deletion palette/benches/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn matrix(c: &mut Criterion) {
b.iter(|| matrix_inverse(*inverse))
});
group.bench_function("rgb_to_xyz_matrix", |b| {
b.iter(|| rgb_to_xyz_matrix::<encoding::Srgb, f32>())
b.iter(rgb_to_xyz_matrix::<encoding::Srgb, f32>)
});
}

Expand Down
13 changes: 6 additions & 7 deletions palette/examples/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
&mut image,
x,
y,
0 * ALPHA_STEPS + alpha_step,
alpha_step,
tile_width,
tile_height,
foreground,
Expand All @@ -56,7 +56,7 @@ fn main() {
&mut image,
x,
y,
1 * ALPHA_STEPS + alpha_step,
ALPHA_STEPS + alpha_step,
tile_width,
tile_height,
Xyza::from_color(foreground),
Expand All @@ -72,6 +72,7 @@ fn main() {
}
}

#[allow(clippy::too_many_arguments)]
fn draw_composed_pixels<C>(
image: &mut image::RgbaImage,
x: u32,
Expand Down Expand Up @@ -106,11 +107,9 @@ fn draw_composed_pixels<C>(
}
}

fn compose<C>(
fg: Alpha<C, f32>,
bg: Alpha<C, f32>,
function: fn(Alpha<C, f32>, Alpha<C, f32>) -> Alpha<C, f32>,
) -> image::Rgba<u8>
type ComposeFn<C> = fn(Alpha<C, f32>, Alpha<C, f32>) -> Alpha<C, f32>;

fn compose<C>(fg: Alpha<C, f32>, bg: Alpha<C, f32>, function: ComposeFn<C>) -> image::Rgba<u8>
where
Alpha<C, f32>: Blend + IntoColor<LinSrgba>,
{
Expand Down
6 changes: 3 additions & 3 deletions palette/examples/color_scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ fn blit_shades(color: LinSrgb<f32>, mut canvas: SubImage<&mut RgbImage>) {
let primary = Srgb::from_linear(color).into();

//Generate one lighter and two darker versions of the color
let light = Srgb::from_linear(color.lighten(0.1).into()).into();
let dark1 = Srgb::from_linear(color.darken(0.1).into()).into();
let dark2 = Srgb::from_linear(color.darken(0.2).into()).into();
let light = Srgb::from_linear(color.lighten(0.1)).into();
let dark1 = Srgb::from_linear(color.darken(0.1)).into();
let dark2 = Srgb::from_linear(color.darken(0.2)).into();

for x in 0..width {
for y in 0..height {
Expand Down
5 changes: 3 additions & 2 deletions palette/examples/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn main() {
&mut image,
x,
y,
0 * ALPHA_STEPS + alpha_step,
alpha_step,
tile_width,
tile_height,
foreground.into(),
Expand All @@ -67,7 +67,7 @@ fn main() {
&mut image,
x,
y,
1 * ALPHA_STEPS + alpha_step,
ALPHA_STEPS + alpha_step,
tile_width,
tile_height,
Xyza::from_color(foreground).into(),
Expand Down Expand Up @@ -127,6 +127,7 @@ fn main() {
}
}

#[allow(clippy::too_many_arguments)]
fn draw_composed_pixels<C>(
image: &mut image::RgbaImage,
x: u32,
Expand Down
2 changes: 1 addition & 1 deletion palette/examples/readme_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn display_colors(filename: &str, displays: &[DisplayType]) {

let mut image = RgbImage::new(WIDTH, displays.len() as u32 * row_height);

for (i, display) in displays.into_iter().enumerate() {
for (i, display) in displays.iter().enumerate() {
let image = image.sub_image(0, i as u32 * row_height, WIDTH, row_height);
match *display {
DisplayType::Discrete(colors) => {
Expand Down
1 change: 1 addition & 0 deletions palette/src/alpha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use self::alpha::*;
#[doc(no_inline)]
pub use crate::blend::PreAlpha; // Cross-link for visibility.

#[allow(clippy::module_inception)]
mod alpha;

/// A trait for color types that can have or be given transparency (alpha channel).
Expand Down
1 change: 1 addition & 0 deletions palette/src/blend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub use self::{
pre_alpha::PreAlpha,
};

#[allow(clippy::module_inception)]
mod blend;
mod blend_with;
mod compose;
Expand Down
4 changes: 2 additions & 2 deletions palette/src/blend/equations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ where
.apply_to(source.clone(), destination.clone());

(
alpha_src_param.mul_constant(source.alpha.clone()),
alpha_dst_param.mul_constant(destination.alpha.clone()),
alpha_src_param.mul_constant(source.alpha),
alpha_dst_param.mul_constant(destination.alpha),
)
};

Expand Down
2 changes: 1 addition & 1 deletion palette/src/cast/from_into_components_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ where
}
}

impl<'a, T, C> TryComponentsInto<C> for T
impl<T, C> TryComponentsInto<C> for T
where
C: TryFromComponents<T>,
{
Expand Down
11 changes: 6 additions & 5 deletions palette/src/color_difference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,12 @@ mod test {
assert!(c1.has_enhanced_contrast_text(white));
assert!(c1.has_enhanced_contrast_large_text(white));
assert!(c1.has_min_contrast_graphics(white));
assert!(c1.has_min_contrast_text(black) == false);
assert!(c1.has_min_contrast_large_text(black) == false);
assert!(c1.has_enhanced_contrast_text(black) == false);
assert!(c1.has_enhanced_contrast_large_text(black) == false);
assert!(c1.has_min_contrast_graphics(black) == false);

assert!(!c1.has_min_contrast_text(black));
assert!(!c1.has_min_contrast_large_text(black));
assert!(!c1.has_enhanced_contrast_text(black));
assert!(!c1.has_enhanced_contrast_large_text(black));
assert!(!c1.has_min_contrast_graphics(black));

let c1 = Srgb::from_str("#066").unwrap().into_format();

Expand Down
20 changes: 9 additions & 11 deletions palette/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,17 @@
//! }
//! }
//!
//! fn main() {
//! // Start with an Xyz100 color.
//! let xyz = Xyz100 {
//! x: 59,
//! y: 75,
//! z: 42,
//! };
//! // Start with an Xyz100 color.
//! let xyz = Xyz100 {
//! x: 59,
//! y: 75,
//! z: 42,
//! };
//!
//! // Convert the color to sRGB.
//! let rgb: Srgb = xyz.into_color();
//! // Convert the color to sRGB.
//! let rgb: Srgb = xyz.into_color();
//!
//! assert_eq!(rgb.into_format(), Srgb::new(196u8, 238, 154));
//! }
//! assert_eq!(rgb.into_format(), Srgb::new(196u8, 238, 154));
//! ```
//!
//! With generic components:
Expand Down
3 changes: 2 additions & 1 deletion palette/src/convert/from_into_color_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ where
///
/// This reuses the memory space, and the returned scope guard will restore
/// the converted colors to their original type when it's dropped.
#[allow(clippy::wrong_self_convention)]
#[must_use]
fn into_color_mut(&mut self) -> FromColorMutGuard<T, Self>;
}
Expand Down Expand Up @@ -308,7 +309,7 @@ where
.and_then(|mut guard| guard.current.take());

if let Some(restored) = restored {
return restored;
restored
} else {
unreachable!()
}
Expand Down
1 change: 1 addition & 0 deletions palette/src/convert/from_into_color_unclamped_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ where
///
/// This reuses the memory space, and the returned scope guard will restore
/// the converted colors to their original type when it's dropped.
#[allow(clippy::wrong_self_convention)]
#[must_use]
fn into_color_unclamped_mut(&mut self) -> FromColorUnclampedMutGuard<T, Self>;
}
Expand Down
2 changes: 0 additions & 2 deletions palette/src/convert/try_from_into_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ pub trait TryFromColor<T>: Sized {
/// }
/// };
/// ```
#[must_use]
fn try_from_color(t: T) -> Result<Self, OutOfBounds<Self>>;
}

Expand Down Expand Up @@ -105,7 +104,6 @@ pub trait TryIntoColor<T>: Sized {
/// }
/// };
/// ```
#[must_use]
fn try_into_color(self) -> Result<T, OutOfBounds<T>>;
}

Expand Down
2 changes: 1 addition & 1 deletion palette/src/hsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ where
// branch we should be in. This makes the sum of all three combine as
// expected.
let red_m = lazy_select! {
if x.clone() => y.clone().select(red.clone(), -red),
if x => y.clone().select(red.clone(), -red),
else => T::zero(),
};
let green_m = lazy_select! {
Expand Down
2 changes: 1 addition & 1 deletion palette/src/hsv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ where
// branch we should be in. This makes the sum of all three combine as
// expected.
let red_m = lazy_select! {
if x.clone() => y.clone().select(red.clone(), -red),
if x => y.clone().select(red.clone(), -red),
else => T::zero(),
};
let green_m = lazy_select! {
Expand Down
33 changes: 20 additions & 13 deletions palette/src/hues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,31 +287,38 @@ macro_rules! make_hues {
}
}

impl Into<f64> for $name<f64> {
impl From<$name<f64>> for f64 {
#[inline]
fn into(self) -> f64 {
self.0.normalize_signed_angle()
fn from(hue: $name<f64>) -> f64 {
hue.0.normalize_signed_angle()
}
}

impl Into<f32> for $name<f32> {
impl From<$name<f32>> for f64 {
#[inline]
fn into(self) -> f32 {
self.0.normalize_signed_angle()
fn from(hue: $name<f32>) -> f64 {
hue.0.normalize_signed_angle() as f64
}
}

impl Into<f32> for $name<f64> {
impl From<$name<f32>> for f32 {
#[inline]
fn into(self) -> f32 {
self.0.normalize_signed_angle() as f32
fn from(hue: $name<f32>) -> f32 {
hue.0.normalize_signed_angle()
}
}

impl Into<u8> for $name<u8> {
impl From<$name<f64>> for f32 {
#[inline]
fn into(self) -> u8 {
self.0
fn from(hue: $name<f64>) -> f32 {
hue.0.normalize_signed_angle() as f32
}
}

impl From<$name<u8>> for u8 {
#[inline]
fn from(hue: $name<u8>) -> u8 {
hue.0
}
}

Expand Down Expand Up @@ -893,7 +900,7 @@ mod test {
assert!(degs > -180.0 && degs <= 180.0);

let pos_degs = hue.into_positive_degrees();
assert!(pos_degs >= 0.0 && pos_degs < 360.0);
assert!((0.0..360.0).contains(&pos_degs));

assert_relative_eq!(RgbHue::from(degs), RgbHue::from(pos_degs));
}
Expand Down
4 changes: 2 additions & 2 deletions palette/src/hwb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ where

#[rustfmt::skip]
fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
let equal_shade = self.whiteness.ulps_eq(&other.whiteness, epsilon.clone(), max_ulps.clone())
&& self.blackness.ulps_eq(&other.blackness, epsilon.clone(), max_ulps.clone());
let equal_shade = self.whiteness.ulps_eq(&other.whiteness, epsilon.clone(), max_ulps)
&& self.blackness.ulps_eq(&other.blackness, epsilon.clone(), max_ulps);

// The hue doesn't matter that much when the color is gray, and may fluctuate
// due to precision errors. This is a blunt tool, but works for now.
Expand Down
10 changes: 5 additions & 5 deletions palette/src/lch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,11 @@ mod test {

#[test]
fn check_min_max_components() {
assert_relative_eq!(Lch::<D65, f32>::min_l(), 0.0);
assert_relative_eq!(Lch::<D65, f32>::max_l(), 100.0);
assert_relative_eq!(Lch::<D65, f32>::min_chroma(), 0.0);
assert_relative_eq!(Lch::<D65, f32>::max_chroma(), 128.0);
assert_relative_eq!(Lch::<D65, f32>::max_extended_chroma(), 181.01933598375618);
assert_relative_eq!(Lch::<D65, f64>::min_l(), 0.0);
assert_relative_eq!(Lch::<D65, f64>::max_l(), 100.0);
assert_relative_eq!(Lch::<D65, f64>::min_chroma(), 0.0);
assert_relative_eq!(Lch::<D65, f64>::max_chroma(), 128.0);
assert_relative_eq!(Lch::<D65, f64>::max_extended_chroma(), 181.01933598375618);
}

struct_of_arrays_tests!(
Expand Down
1 change: 1 addition & 0 deletions palette/src/luma.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Types for luma and luminance (grayscale) values.

pub mod channels;
#[allow(clippy::module_inception)]
mod luma;

use crate::encoding::{Gamma, Linear, Srgb};
Expand Down
Loading

0 comments on commit aae68da

Please sign in to comment.