Skip to content

Commit

Permalink
Clippy (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski authored Dec 10, 2024
1 parent 7495e4b commit 5414013
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 22 deletions.
10 changes: 1 addition & 9 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ allow = [
"BSD-2-Clause",
"BSD-3-Clause",
"MIT",
"MIT-0",
"MPL-2.0",
"Unicode-DFS-2016",
"Unicode-3.0",
]

[[licenses.exceptions]]
allow = ["WTFPL"]
name = "pcx"
version = "*"

[advisories]
yanked = "deny"
ignore = []
Expand All @@ -41,5 +34,4 @@ deny = []
skip = [
{ name = "bitflags" }, # Some deps depend on 1.3.2 while others on 2.6.0
{ name = "hashbrown" }, # Some deps depend on 0.13.2 while others on 0.14.5
{ name = "miniz_oxide" } # Some deps depend on 0.7.4 while others on 0.8.0
]
2 changes: 1 addition & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ where
/// the bounds will not overflow.
fn check_image_fits(width: u32, height: u32, len: usize) -> bool {
let checked_len = Self::image_buffer_len(width, height);
checked_len.map_or(false, |min_len| min_len <= len)
checked_len.is_some_and(|min_len| min_len <= len)
}

fn image_buffer_len(width: u32, height: u32) -> Option<usize> {
Expand Down
2 changes: 1 addition & 1 deletion src/codecs/avif/yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ fn process_halved_chroma_row<
// preventing accidental use of invalid values from the trailing region.

let y_plane = &image.y_plane[0..image.width];
let chroma_size = image.width.div_ceil(2);
let chroma_size = (image.width + 1) / 2;
let u_plane = &image.u_plane[0..chroma_size];
let v_plane = &image.v_plane[0..chroma_size];
let rgba = &mut rgba[0..image.width * CHANNELS];
Expand Down
4 changes: 2 additions & 2 deletions src/codecs/pnm/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,8 @@ where

let token = reader
.bytes()
.skip_while(|v| v.as_ref().ok().map_or(false, is_separator))
.take_while(|v| v.as_ref().ok().map_or(false, |c| !is_separator(c)))
.skip_while(|v| v.as_ref().ok().is_some_and(is_separator))
.take_while(|v| v.as_ref().ok().is_some_and(|c| !is_separator(c)))
.collect::<Result<Vec<u8>, _>>()?;

if !token.is_ascii() {
Expand Down
1 change: 1 addition & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl<T: Primitive> FromPrimitive<T> for T {
// 1.0 (white) was picked as firefox and chrome choose to map NaN to that.
#[inline]
fn normalize_float(float: f32, max: f32) -> f32 {
#[allow(clippy::neg_cmp_op_on_partial_ord)]
let clamped = if !(float < 1.0) { 1.0 } else { float.max(0.0) };
(clamped * max).round()
}
Expand Down
12 changes: 3 additions & 9 deletions src/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl SampleLayout {
/// Check if a buffer of length `len` is large enough.
#[must_use]
pub fn fits(&self, len: usize) -> bool {
self.min_length().map_or(false, |min| len >= min)
self.min_length().is_some_and(|min| len >= min)
}

/// The extents of this array, in order of increasing strides.
Expand Down Expand Up @@ -747,10 +747,7 @@ impl<Buffer> FlatSamples<Buffer> {
where
Buffer: AsRef<[T]>,
{
let min_length = match self.min_length() {
None => return None,
Some(index) => index,
};
let min_length = self.min_length()?;

let slice = self.samples.as_ref();
if slice.len() < min_length {
Expand All @@ -765,10 +762,7 @@ impl<Buffer> FlatSamples<Buffer> {
where
Buffer: AsMut<[T]>,
{
let min_length = match self.min_length() {
None => return None,
Some(index) => index,
};
let min_length = self.min_length()?;

let slice = self.samples.as_mut();
if slice.len() < min_length {
Expand Down
1 change: 1 addition & 0 deletions src/imageops/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ where
let max = S::DEFAULT_MAX_VALUE;
let max: f32 = NumCast::from(max).unwrap();

#[allow(clippy::redundant_guards)]
let sum = match kernel.iter().fold(0.0, |s, &item| s + item) {
x if x == 0.0 => 1.0,
sum => sum,
Expand Down

0 comments on commit 5414013

Please sign in to comment.