Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another batch of Clippy #2400

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl<'a> Frames<'a> {

impl Iterator for Frames<'_> {
type Item = ImageResult<Frame>;

fn next(&mut self) -> Option<ImageResult<Frame>> {
self.iterator.next()
}
Expand Down Expand Up @@ -356,7 +357,7 @@ impl Ord for Ratio {
// We cast the types from `u32` to `u64` in order
// to not overflow the multiplications.

(a as u64 * d as u64).cmp(&(c as u64 * b as u64))
(u64::from(a) * u64::from(d)).cmp(&(u64::from(c) * u64::from(b)))
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ mod test {
fn slice_buffer() {
let data = [0; 9];
let buf: ImageBuffer<Luma<u8>, _> = ImageBuffer::from_raw(3, 3, &data[..]).unwrap();
assert_eq!(&*buf, &data[..])
assert_eq!(&*buf, &data[..]);
}

macro_rules! new_buffer_zero_test {
Expand Down Expand Up @@ -1535,7 +1535,7 @@ mod test {
let b = a.get_mut(3 * 10).unwrap();
*b = 255;
}
assert_eq!(a.get_pixel(0, 1)[0], 255)
assert_eq!(a.get_pixel(0, 1)[0], 255);
}

#[test]
Expand Down
20 changes: 0 additions & 20 deletions src/codecs/avif/yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ fn qrshr<const PRECISION: i32, const BIT_DEPTH: usize>(val: i32) -> i32 {
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv400_to_rgba8(
image: YuvPlanarImage<u8>,
rgba: &mut [u8],
Expand All @@ -286,7 +285,6 @@ pub(crate) fn yuv400_to_rgba8(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv400_to_rgba10(
image: YuvPlanarImage<u16>,
rgba: &mut [u16],
Expand All @@ -307,7 +305,6 @@ pub(crate) fn yuv400_to_rgba10(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv400_to_rgba12(
image: YuvPlanarImage<u16>,
rgba: &mut [u16],
Expand All @@ -328,7 +325,6 @@ pub(crate) fn yuv400_to_rgba12(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
#[inline]
fn yuv400_to_rgbx_impl<
V: Copy + AsPrimitive<i32> + 'static + Sized,
Expand Down Expand Up @@ -447,7 +443,6 @@ where
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv420_to_rgba8(
image: YuvPlanarImage<u8>,
rgb: &mut [u8],
Expand All @@ -468,7 +463,6 @@ pub(crate) fn yuv420_to_rgba8(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv420_to_rgba10(
image: YuvPlanarImage<u16>,
rgb: &mut [u16],
Expand All @@ -489,7 +483,6 @@ pub(crate) fn yuv420_to_rgba10(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv420_to_rgba12(
image: YuvPlanarImage<u16>,
rgb: &mut [u16],
Expand Down Expand Up @@ -628,7 +621,6 @@ fn process_halved_chroma_row<
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
#[inline]
fn yuv420_to_rgbx<
V: Copy + AsPrimitive<i32> + 'static + Sized,
Expand Down Expand Up @@ -790,7 +782,6 @@ where
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv422_to_rgba8(
image: YuvPlanarImage<u8>,
rgb: &mut [u8],
Expand All @@ -811,7 +802,6 @@ pub(crate) fn yuv422_to_rgba8(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv422_to_rgba10(
image: YuvPlanarImage<u16>,
rgb: &mut [u16],
Expand All @@ -832,7 +822,6 @@ pub(crate) fn yuv422_to_rgba10(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv422_to_rgba12(
image: YuvPlanarImage<u16>,
rgb: &mut [u16],
Expand All @@ -853,7 +842,6 @@ pub(crate) fn yuv422_to_rgba12(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
fn yuv422_to_rgbx_impl<
V: Copy + AsPrimitive<i32> + 'static + Sized,
const CHANNELS: usize,
Expand Down Expand Up @@ -979,7 +967,6 @@ where
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(crate) fn yuv444_to_rgba8(
image: YuvPlanarImage<u8>,
rgba: &mut [u8],
Expand All @@ -1004,7 +991,6 @@ pub(crate) fn yuv444_to_rgba8(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(super) fn yuv444_to_rgba10(
image: YuvPlanarImage<u16>,
rgba: &mut [u16],
Expand All @@ -1029,7 +1015,6 @@ pub(super) fn yuv444_to_rgba10(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
pub(super) fn yuv444_to_rgba12(
image: YuvPlanarImage<u16>,
rgba: &mut [u16],
Expand All @@ -1054,7 +1039,6 @@ pub(super) fn yuv444_to_rgba12(
/// * `range`: see [YuvIntensityRange]
/// * `matrix`: see [YuvStandardMatrix]
///
///
#[inline]
fn yuv444_to_rgbx_impl<
V: Copy + AsPrimitive<i32> + 'static + Sized,
Expand Down Expand Up @@ -1172,7 +1156,6 @@ where
/// * `rgb`: RGB image layout
/// * `range`: see [YuvIntensityRange]
///
///
fn gbr_to_rgba8(
image: YuvPlanarImage<u8>,
rgb: &mut [u8],
Expand All @@ -1191,7 +1174,6 @@ fn gbr_to_rgba8(
/// * `rgba`: RGBx image layout
/// * `range`: see [YuvIntensityRange]
///
///
fn gbr_to_rgba10(
image: YuvPlanarImage<u16>,
rgba: &mut [u16],
Expand All @@ -1210,7 +1192,6 @@ fn gbr_to_rgba10(
/// * `rgba`: RGBx image layout
/// * `range`: see [YuvIntensityRange]
///
///
fn gbr_to_rgba12(
image: YuvPlanarImage<u16>,
rgba: &mut [u16],
Expand All @@ -1229,7 +1210,6 @@ fn gbr_to_rgba12(
/// * `rgb`: RGB image layout
/// * `range`: see [YuvIntensityRange]
///
///
#[inline]
fn gbr_to_rgbx_impl<
V: Copy + AsPrimitive<i32> + 'static + Sized,
Expand Down
8 changes: 4 additions & 4 deletions src/codecs/bmp/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ fn set_1bit_pixel_run<'a, T: Iterator<Item = &'a u8>>(
let mut bit = 0x80;
loop {
if let Some(pixel) = pixel_iter.next() {
let rgb = palette[((idx & bit) != 0) as usize];
let rgb = palette[usize::from((idx & bit) != 0)];
pixel[0] = rgb[0];
pixel[1] = rgb[1];
pixel[2] = rgb[2];
Expand Down Expand Up @@ -432,7 +432,7 @@ impl Bitfield {
4 => LOOKUP_TABLE_4_BIT_TO_8_BIT[(data & 0b00_1111) as usize],
5 => LOOKUP_TABLE_5_BIT_TO_8_BIT[(data & 0b01_1111) as usize],
6 => LOOKUP_TABLE_6_BIT_TO_8_BIT[(data & 0b11_1111) as usize],
7 => ((data & 0x7f) << 1 | (data & 0x7f) >> 6) as u8,
7 => (((data & 0x7f) << 1) | ((data & 0x7f) >> 6)) as u8,
8 => (data & 0xff) as u8,
_ => panic!(),
}
Expand Down Expand Up @@ -1389,9 +1389,9 @@ mod test {
let bitfield = Bitfield { shift: 0, len };
for i in 0..(1 << len) {
let read = bitfield.read(i);
let calc = (i as f64 / ((1 << len) - 1) as f64 * 255f64).round() as u8;
let calc = (f64::from(i) / f64::from((1 << len) - 1) * 255f64).round() as u8;
if read != calc {
println!("len:{} i:{} read:{} calc:{}", len, i, read, calc);
println!("len:{len} i:{i} read:{read} calc:{calc}");
}
assert_eq!(read, calc);
}
Expand Down
1 change: 0 additions & 1 deletion src/codecs/bmp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! # Related Links
//! * <https://msdn.microsoft.com/en-us/library/windows/desktop/dd183375%28v=vs.85%29.aspx>
//! * <https://en.wikipedia.org/wiki/BMP_file_format>
//!

pub use self::decoder::BmpDecoder;
pub use self::encoder::BmpEncoder;
Expand Down
1 change: 1 addition & 0 deletions src/codecs/gif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ impl<R> Read for GifReader<R> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.0.read(buf)
}

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
if self.0.position() == 0 && buf.is_empty() {
mem::swap(buf, self.0.get_mut());
Expand Down
1 change: 1 addition & 0 deletions src/codecs/hdr/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl<'a> NorunCombineIterator<'a> {
// Combines sequential noruns produced by RunIterator
impl Iterator for NorunCombineIterator<'_> {
type Item = RunOrNot;

fn next(&mut self) -> Option<Self::Item> {
loop {
match self.prev.take() {
Expand Down
1 change: 0 additions & 1 deletion src/codecs/hdr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//!
//! * <http://radsite.lbl.gov/radiance/refer/filefmts.pdf>
//! * <http://www.graphics.cornell.edu/~bjw/rgbe/rgbe.c>
//!

mod decoder;
mod encoder;
Expand Down
14 changes: 7 additions & 7 deletions src/codecs/jpeg/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,9 @@ fn encode_coefficient(coefficient: i32) -> (u8, u16) {
#[inline]
fn rgb_to_ycbcr<P: Pixel>(pixel: P) -> (u8, u8, u8) {
let [r, g, b] = pixel.to_rgb().0;
let r: i32 = r.to_u8().unwrap() as i32;
let g: i32 = g.to_u8().unwrap() as i32;
let b: i32 = b.to_u8().unwrap() as i32;
let r: i32 = i32::from(r.to_u8().unwrap());
let g: i32 = i32::from(g.to_u8().unwrap());
let b: i32 = i32::from(b.to_u8().unwrap());

/*
JPEG RGB -> YCbCr is defined as following equations using Bt.601 Full Range matrix:
Expand Down Expand Up @@ -1016,7 +1016,7 @@ mod tests {
let result = encoder.write_image(&img, 65_536, 1, ExtendedColorType::L8);
match result {
Err(ImageError::Parameter(err)) => {
assert_eq!(err.kind(), DimensionMismatch)
assert_eq!(err.kind(), DimensionMismatch);
}
other => {
panic!(
Expand Down Expand Up @@ -1065,7 +1065,7 @@ mod tests {
build_frame_header(&mut buf, 5, 100, 150, &components);
assert_eq!(
buf,
[5, 0, 150, 0, 100, 2, 1, 1 << 4 | 1, 5, 2, 1 << 4 | 1, 4]
[5, 0, 150, 0, 100, 2, 1, (1 << 4) | 1, 5, 2, (1 << 4) | 1, 4]
);
}

Expand Down Expand Up @@ -1093,7 +1093,7 @@ mod tests {
},
];
build_scan_header(&mut buf, &components);
assert_eq!(buf, [2, 1, 5 << 4 | 5, 2, 4 << 4 | 4, 0, 63, 0]);
assert_eq!(buf, [2, 1, (5 << 4) | 5, 2, (4 << 4) | 4, 0, 63, 0]);
}

#[test]
Expand Down Expand Up @@ -1123,7 +1123,7 @@ mod tests {
let mut expected = vec![];
expected.push(1);
expected.extend_from_slice(&[0; 64]);
assert_eq!(buf, expected)
assert_eq!(buf, expected);
}

#[cfg(feature = "benchmarks")]
Expand Down
1 change: 0 additions & 1 deletion src/codecs/jpeg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//!
//! # Related Links
//! * <http://www.w3.org/Graphics/JPEG/itu-t81.pdf> - The JPEG specification
//!

pub use self::decoder::JpegDecoder;
pub use self::encoder::{JpegEncoder, PixelDensity, PixelDensityUnit};
Expand Down
1 change: 0 additions & 1 deletion src/codecs/png.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//!
//! # Related Links
//! * <http://www.w3.org/TR/PNG/> - The PNG Specification
//!

use std::borrow::Cow;
use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion src/codecs/pnm/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ fn read_separated_ascii<T: FromStr<Err = ParseIntError>>(reader: &mut dyn Read)
where
T::Err: Display,
{
let is_separator = |v: &u8| matches! { *v, b'\t' | b'\n' | b'\x0b' | b'\x0c' | b'\r' | b' ' };
let is_separator = |v: &u8| matches!(*v, b'\t' | b'\n' | b'\x0b' | b'\x0c' | b'\r' | b' ');

let token = reader
.bytes()
Expand Down
2 changes: 1 addition & 1 deletion src/codecs/tga/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<R: Read> TgaDecoder<R> {
fn bytes_to_index(bytes: &[u8]) -> usize {
let mut result = 0usize;
for byte in bytes {
result = result << 8 | *byte as usize;
result = (result << 8) | *byte as usize;
}
result
}
Expand Down
4 changes: 1 addition & 3 deletions src/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ impl<'buf, Subpixel> FlatSamples<&'buf [Subpixel]> {
/// use image::{flat::FlatSamples, GenericImage, RgbImage, Rgb};
///
/// let background = Rgb([20, 20, 20]);
/// let bg = FlatSamples::with_monocolor(&background, 200, 200);;
/// let bg = FlatSamples::with_monocolor(&background, 200, 200);
///
/// let mut image = RgbImage::new(200, 200);
/// paint_something(&mut image);
Expand Down Expand Up @@ -986,7 +986,6 @@ impl<'buf, Subpixel> FlatSamples<&'buf [Subpixel]> {
///
/// * For all indices inside bounds, the corresponding index is valid in the buffer
/// * `P::channel_count()` agrees with `self.inner.layout.channels`
///
#[derive(Clone, Debug)]
pub struct View<Buffer, P: Pixel>
where
Expand All @@ -1009,7 +1008,6 @@ where
/// * There is no aliasing of samples
/// * The samples are packed, i.e. `self.inner.layout.sample_stride == 1`
/// * `P::channel_count()` agrees with `self.inner.layout.channels`
///
#[derive(Clone, Debug)]
pub struct ViewMut<Buffer, P: Pixel>
where
Expand Down
3 changes: 2 additions & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ impl<I: ?Sized> Clone for Pixels<'_, I> {
/// use image::{GenericImageView, Rgb, RgbImage};
///
/// let buffer = RgbImage::new(10, 10);
/// let image: &dyn GenericImageView<Pixel=Rgb<u8>> = &buffer;
/// let image: &dyn GenericImageView<Pixel = Rgb<u8>> = &buffer;
/// ```
pub trait GenericImageView {
/// The type of pixel.
Expand Down Expand Up @@ -1269,6 +1269,7 @@ where
I: Deref,
{
type Target = SubImageInner<I>;

fn deref(&self) -> &Self::Target {
&self.inner
}
Expand Down
Loading
Loading