Skip to content

Add clippy to build action. #282

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

Merged
merged 2 commits into from
Mar 15, 2021
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
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ jobs:
submodules: recursive

- name: Install Rust
run: rustup toolchain install ${{ matrix.rust }} --profile minimal --component rustfmt
run: rustup toolchain install ${{ matrix.rust }} --profile minimal --component rustfmt clippy

- name: Check format
shell: bash
run: rustup run ${{ matrix.rust }} cargo fmt --all -- --check

- name: Clippy
shell: bash
run: rustup run ${{ matrix.rust }} cargo clippy --all -- -D warnings

- name: Test (release)
shell: bash
run: rustup run ${{ matrix.rust }} cargo test --all --verbose --release
Expand Down
2 changes: 1 addition & 1 deletion mp4parse/benches/avif_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use std::fs::File;

fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("avif_largest", |b| b.iter(|| avif_largest()));
c.bench_function("avif_largest", |b| b.iter(avif_largest));
}

criterion_group!(benches, criterion_benchmark);
Expand Down
8 changes: 4 additions & 4 deletions mp4parse/src/boxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ macro_rules! box_database {
}
}

impl Into<u32> for BoxType {
fn into(self) -> u32 {
impl From<BoxType> for u32 {
fn from(b: BoxType) -> u32 {
use self::BoxType::*;
match self {
match b {
$($(#[$attr])* $boxenum => $boxtype),*,
UnknownBox(t) => t,
}
Expand All @@ -46,7 +46,7 @@ macro_rules! box_database {

impl fmt::Debug for BoxType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let fourcc: FourCC = From::from(self.clone());
let fourcc: FourCC = From::from(*self);
fourcc.fmt(f)
}
}
Expand Down
23 changes: 18 additions & 5 deletions mp4parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// `clippy::upper_case_acronyms` is a nightly-only lint as of 2021-03-15, so we
// allow `clippy::unknown_clippy_lints` to ignore it on stable - but
// `clippy::unknown_clippy_lints` has been renamed in nightly, so we need to
// allow `renamed_and_removed_lints` to ignore a warning for that.
#![allow(renamed_and_removed_lints)]
#![allow(clippy::unknown_clippy_lints)]
#![allow(clippy::upper_case_acronyms)]

#[macro_use]
extern crate log;

Expand Down Expand Up @@ -41,6 +49,8 @@ const TABLE_SIZE_LIMIT: u32 = 30 * 60 * 60 * 24 * 7;
/// A trait to indicate a type can be infallibly converted to `u64`.
/// This should only be implemented for infallible conversions, so only unsigned types are valid.
trait ToU64 {
// Remove when https://github.com/rust-lang/rust-clippy/issues/6727 is resolved
#[allow(clippy::wrong_self_convention)]
fn to_u64(self) -> u64;
}

Expand All @@ -59,6 +69,8 @@ impl ToU64 for usize {
/// A trait to indicate a type can be infallibly converted to `usize`.
/// This should only be implemented for infallible conversions, so only unsigned types are valid.
pub trait ToUsize {
// Remove when https://github.com/rust-lang/rust-clippy/issues/6727 is resolved
#[allow(clippy::wrong_self_convention)]
fn to_usize(self) -> usize;
}

Expand Down Expand Up @@ -803,7 +815,7 @@ impl AvifContext {
"AvifItem::Location requires the location exists in AvifContext::item_storage"
);
}
AvifItem::Data(data) => return data.as_slice(),
AvifItem::Data(data) => data.as_slice(),
}
}
}
Expand Down Expand Up @@ -1923,8 +1935,8 @@ impl std::ops::Add<U32MulU16> for U32MulU8 {

fn add(self, rhs: U32MulU16) -> Self::Output {
static_assertions::const_assert!(U32MulU8::MAX + U32MulU16::MAX < U64::MAX);
let lhs: u64 = self.get().into();
let rhs: u64 = rhs.get().into();
let lhs: u64 = self.get();
let rhs: u64 = rhs.get();
Self::Output::new(lhs.checked_add(rhs).expect("infallible"))
}
}
Expand Down Expand Up @@ -2003,6 +2015,7 @@ fn read_ipma<T: Read>(
};

if let Some(previous_association) = associations.last() {
#[allow(clippy::comparison_chain)]
if previous_association.item_id > item_id {
return Err(Error::InvalidData(
"Each ItemPropertyAssociation box shall be ordered by increasing item_ID",
Expand Down Expand Up @@ -2088,7 +2101,7 @@ fn read_pixi<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<u8>> {
let mut channels = TryVec::with_capacity(num_channels)?;
let num_channels_read = src.try_read_to_end(&mut channels)?;

if num_channels_read != num_channels.into() {
if num_channels_read != num_channels {
return Err(Error::InvalidData("invalid num_channels"));
}

Expand Down Expand Up @@ -3711,7 +3724,7 @@ fn read_qt_wave_atom<T: Read>(src: &mut BMFFBox<T>) -> Result<ES_Descriptor> {
}
}

codec_specific.ok_or_else(|| Error::InvalidData("malformed audio sample entry"))
codec_specific.ok_or(Error::InvalidData("malformed audio sample entry"))
}

/// Parse an audio description inside an stsd box.
Expand Down
34 changes: 10 additions & 24 deletions mp4parse_capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,14 +998,10 @@ fn get_track_audio_info(
sample_info.protected_data.is_encrypted = tenc.is_encrypted;
sample_info.protected_data.iv_size = tenc.iv_size;
sample_info.protected_data.kid.set_data(&(tenc.kid));
sample_info.protected_data.crypt_byte_block = match tenc.crypt_byte_block_count {
Some(n) => n,
None => 0,
};
sample_info.protected_data.skip_byte_block = match tenc.skip_byte_block_count {
Some(n) => n,
None => 0,
};
sample_info.protected_data.crypt_byte_block =
tenc.crypt_byte_block_count.unwrap_or(0);
sample_info.protected_data.skip_byte_block =
tenc.skip_byte_block_count.unwrap_or(0);
if let Some(ref iv_vec) = tenc.constant_iv {
if iv_vec.len() > std::u32::MAX as usize {
return Err(Mp4parseStatus::Invalid);
Expand Down Expand Up @@ -1164,14 +1160,10 @@ fn mp4parse_get_track_video_info_safe(
sample_info.protected_data.is_encrypted = tenc.is_encrypted;
sample_info.protected_data.iv_size = tenc.iv_size;
sample_info.protected_data.kid.set_data(&(tenc.kid));
sample_info.protected_data.crypt_byte_block = match tenc.crypt_byte_block_count {
Some(n) => n,
None => 0,
};
sample_info.protected_data.skip_byte_block = match tenc.skip_byte_block_count {
Some(n) => n,
None => 0,
};
sample_info.protected_data.crypt_byte_block =
tenc.crypt_byte_block_count.unwrap_or(0);
sample_info.protected_data.skip_byte_block =
tenc.skip_byte_block_count.unwrap_or(0);
if let Some(ref iv_vec) = tenc.constant_iv {
if iv_vec.len() > std::u32::MAX as usize {
return Err(Mp4parseStatus::Invalid);
Expand Down Expand Up @@ -1514,10 +1506,7 @@ fn create_sample_table(
};

// According to spec, no sync table means every sample is sync sample.
let has_sync_table = match track.stss {
Some(_) => true,
_ => false,
};
let has_sync_table = matches!(track.stss, Some(_));

let mut sample_size_iter = stsz.sample_sizes.iter();

Expand Down Expand Up @@ -1575,10 +1564,7 @@ fn create_sample_table(
}
}

let ctts_iter = match track.ctts {
Some(ref v) => Some(v.samples.as_slice().iter()),
_ => None,
};
let ctts_iter = track.ctts.as_ref().map(|v| v.samples.as_slice().iter());

let mut ctts_offset_iter = TimeOffsetIterator {
cur_sample_range: (0..0),
Expand Down