Skip to content

Commit

Permalink
Merge pull request #1439 from HeroicKatora/activate-clippy
Browse files Browse the repository at this point in the history
Activate clippy
  • Loading branch information
HeroicKatora committed Feb 23, 2021
2 parents 4b281a3 + f62f939 commit 150f890
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 60 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,21 @@ jobs:
env:
SYSTEM_DEPS_DAV1D_BUILD_INTERNAL: always
clippy:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: install-dependencies
run: sudo apt update && sudo apt install ninja-build meson nasm
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: clippy
- name: Run clippy check
uses: actions-rs/cargo@v1
- uses: actions-rs/cargo@v1
with:
command: clippy
args: clippy --all-features -- -D warnings
env:
SYSTEM_DEPS_DAV1D_BUILD_INTERNAL: always
build_fuzz_afl:
name: "Fuzz targets (afl)"
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.34.2"
63 changes: 37 additions & 26 deletions src/codecs/ico/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,20 @@ enum InnerDecoder<R: Read> {
struct DirEntry {
width: u8,
height: u8,
// We ignore some header fields as they will be replicated in the PNG, BMP and they are not
// necessary for determining the best_entry.
#[allow(unused)]
color_count: u8,
// Wikipedia has this to say:
// Although Microsoft's technical documentation states that this value must be zero, the icon
// encoder built into .NET (System.Drawing.Icon.Save) sets this value to 255. It appears that
// the operating system ignores this value altogether.
#[allow(unused)]
reserved: u8,

// We ignore some header fields as they will be replicated in the PNG, BMP and they are not
// necessary for determining the best_entry.
#[allow(unused)]
num_color_planes: u16,
bits_per_pixel: u16,

Expand Down Expand Up @@ -148,32 +159,32 @@ fn read_entries<R: Read>(r: &mut R) -> ImageResult<Vec<DirEntry>> {
}

fn read_entry<R: Read>(r: &mut R) -> ImageResult<DirEntry> {
let mut entry = DirEntry::default();

entry.width = r.read_u8()?;
entry.height = r.read_u8()?;
entry.color_count = r.read_u8()?;
// Reserved value (not used)
entry.reserved = r.read_u8()?;

// This may be either the number of color planes (0 or 1), or the horizontal coordinate
// of the hotspot for CUR files.
entry.num_color_planes = r.read_u16::<LittleEndian>()?;
if entry.num_color_planes > 256 {
return Err(DecoderError::IcoEntryTooManyPlanesOrHotspot.into());
}

// This may be either the bit depth (may be 0 meaning unspecified),
// or the vertical coordinate of the hotspot for CUR files.
entry.bits_per_pixel = r.read_u16::<LittleEndian>()?;
if entry.bits_per_pixel > 256 {
return Err(DecoderError::IcoEntryTooManyBitsPerPixelOrHotspot.into());
}

entry.image_length = r.read_u32::<LittleEndian>()?;
entry.image_offset = r.read_u32::<LittleEndian>()?;

Ok(entry)
Ok(DirEntry {
width: r.read_u8()?,
height: r.read_u8()?,
color_count: r.read_u8()?,
reserved: r.read_u8()?,
num_color_planes: {
// This may be either the number of color planes (0 or 1), or the horizontal coordinate
// of the hotspot for CUR files.
let num = r.read_u16::<LittleEndian>()?;
if num > 256 {
return Err(DecoderError::IcoEntryTooManyPlanesOrHotspot.into());
}
num
},
bits_per_pixel: {
// This may be either the bit depth (may be 0 meaning unspecified),
// or the vertical coordinate of the hotspot for CUR files.
let num = r.read_u16::<LittleEndian>()?;
if num > 256 {
return Err(DecoderError::IcoEntryTooManyBitsPerPixelOrHotspot.into());
}
num
},
image_length: r.read_u32::<LittleEndian>()?,
image_offset: r.read_u32::<LittleEndian>()?,
})
}

/// Find the entry with the highest (color depth, size).
Expand Down
5 changes: 2 additions & 3 deletions src/codecs/pnm/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,12 +661,11 @@ impl<'a> TupleEncoding<'a> {
samples: FlatSamples::U16(samples),
} => samples
.iter()
.map(|&sample| {
.try_for_each(|&sample| {
writer
.write_u16::<BigEndian>(sample)
.map_err(ImageError::IoError)
})
.collect(),
}),

TupleEncoding::Ascii {
samples: FlatSamples::U8(samples),
Expand Down
2 changes: 1 addition & 1 deletion src/codecs/tiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<R> TiffDecoder<R>

fn check_sample_format(sample_format: u16) -> Result<(), ImageError> {
match tiff::tags::SampleFormat::from_u16(sample_format) {
Some(tiff::tags::SampleFormat::Uint) => Ok({}),
Some(tiff::tags::SampleFormat::Uint) => Ok(()),
Some(other) => {
Err(ImageError::Unsupported(UnsupportedError::from_format_and_kind(
ImageFormat::Tiff.into(),
Expand Down
8 changes: 3 additions & 5 deletions src/codecs/webp/vp8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,9 @@ impl<R: Read> Vp8Decoder<R> {
fn read_macroblock_header(&mut self, mbx: usize) -> ImageResult<(bool, MacroBlock)> {
let mut mb = MacroBlock::default();

mb.segmentid = if self.segments_enabled && self.segments_update_map {
self.b
.read_with_tree(&SEGMENT_ID_TREE, &self.segment_tree_probs, 0) as u8
} else {
0
if self.segments_enabled && self.segments_update_map {
mb.segmentid = self.b
.read_with_tree(&SEGMENT_ID_TREE, &self.segment_tree_probs, 0) as u8;
};

let skip_coeff = if self.prob_skip_false.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl ImageFormat {
fn inner(path: &Path) -> ImageResult<ImageFormat> {
let exact_ext = path.extension();
exact_ext
.and_then(|ext| ImageFormat::from_extension(ext))
.and_then(ImageFormat::from_extension)
.ok_or_else(|| {
let format_hint = match exact_ext {
None => ImageFormatHint::Unknown,
Expand Down
34 changes: 14 additions & 20 deletions src/imageops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,11 @@ where
/// ```no_run
/// use image::{RgbaImage};
///
/// fn main() {
/// let mut img = RgbaImage::new(1920, 1080);
/// let tile = image::open("tile.png").unwrap();
/// let mut img = RgbaImage::new(1920, 1080);
/// let tile = image::open("tile.png").unwrap();
///
/// image::imageops::tile(&mut img, &tile);
/// img.save("tiled_wallpaper.png").unwrap();
/// }
/// image::imageops::tile(&mut img, &tile);
/// img.save("tiled_wallpaper.png").unwrap();
/// ```
pub fn tile<I, J>(bottom: &mut I, top: &J)
where
Expand All @@ -202,14 +200,12 @@ where
/// ```no_run
/// use image::{Rgba, RgbaImage, Pixel};
///
/// fn main() {
/// let mut img = RgbaImage::new(100, 100);
/// let start = Rgba::from_slice(&[0, 128, 0, 0]);
/// let end = Rgba::from_slice(&[255, 255, 255, 255]);
/// let mut img = RgbaImage::new(100, 100);
/// let start = Rgba::from_slice(&[0, 128, 0, 0]);
/// let end = Rgba::from_slice(&[255, 255, 255, 255]);
///
/// image::imageops::vertical_gradient(&mut img, start, end);
/// img.save("vertical_gradient.png").unwrap();
/// }
/// image::imageops::vertical_gradient(&mut img, start, end);
/// img.save("vertical_gradient.png").unwrap();
pub fn vertical_gradient<S, P, I>(img: &mut I, start: &P, stop: &P)
where
I: GenericImage<Pixel = P>,
Expand Down Expand Up @@ -237,14 +233,12 @@ where
/// ```no_run
/// use image::{Rgba, RgbaImage, Pixel};
///
/// fn main() {
/// let mut img = RgbaImage::new(100, 100);
/// let start = Rgba::from_slice(&[0, 128, 0, 0]);
/// let end = Rgba::from_slice(&[255, 255, 255, 255]);
/// let mut img = RgbaImage::new(100, 100);
/// let start = Rgba::from_slice(&[0, 128, 0, 0]);
/// let end = Rgba::from_slice(&[255, 255, 255, 255]);
///
/// image::imageops::horizontal_gradient(&mut img, start, end);
/// img.save("horizontal_gradient.png").unwrap();
/// }
/// image::imageops::horizontal_gradient(&mut img, start, end);
/// img.save("horizontal_gradient.png").unwrap();
pub fn horizontal_gradient<S, P, I>(img: &mut I, start: &P, stop: &P)
where
I: GenericImage<Pixel = P>,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
#![cfg_attr(all(test, feature = "benchmarks"), feature(test))]
// it's a bit of a pain otherwise
#![allow(clippy::many_single_char_names)]
// it's a backwards compatibility break
#![allow(clippy::wrong_self_convention, clippy::enum_variant_names)]

#[cfg(all(test, feature = "benchmarks"))]
extern crate test;
Expand Down

0 comments on commit 150f890

Please sign in to comment.