Skip to content

feat: solve remaining clippy warnings and add it to CI #487

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 6 commits into from
Apr 28, 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
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ jobs:
fi
if: matrix.build == 'stable'

rustfmt:
name: Rustfmt & Docs
rustfmt_docs_clippy:
name: Rustfmt, Docs and Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
run: rustup update stable && rustup default stable && rustup component add rustfmt && rustup component add clippy
- run: cargo fmt -- --check
- run: cargo doc --all-features
- run: cargo clippy --all-features -- -D warnings

wasm:
name: WebAssembly
Expand Down
7 changes: 4 additions & 3 deletions src/ffi/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ impl InflateBackend for Inflate {
MZ_OK => Ok(Status::Ok),
MZ_BUF_ERROR => Ok(Status::BufError),
MZ_STREAM_END => Ok(Status::StreamEnd),
#[allow(clippy::unnecessary_cast)]
MZ_NEED_DICT => mem::decompress_need_dict((*raw).adler as u32),
c => panic!("unknown return code: {}", c),
}
Expand Down Expand Up @@ -465,11 +466,11 @@ mod c_backend {
pub const MZ_DEFAULT_WINDOW_BITS: c_int = 15;

#[cfg(feature = "zlib-ng")]
const ZLIB_VERSION: &'static str = "2.1.0.devel\0";
const ZLIB_VERSION: &str = "2.1.0.devel\0";
#[cfg(all(not(feature = "zlib-ng"), feature = "zlib-rs"))]
const ZLIB_VERSION: &'static str = "1.3.0-zlib-rs-0.5.0\0";
const ZLIB_VERSION: &str = "1.3.0-zlib-rs-0.5.0\0";
#[cfg(not(any(feature = "zlib-ng", feature = "zlib-rs")))]
const ZLIB_VERSION: &'static str = "1.2.8\0";
const ZLIB_VERSION: &str = "1.2.8\0";

pub unsafe extern "C" fn mz_deflateInit2(
stream: *mut mz_stream,
Expand Down
6 changes: 3 additions & 3 deletions src/gz/bufread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<R: BufRead> GzEncoder<R> {
calced_crc_bytes[1],
calced_crc_bytes[2],
calced_crc_bytes[3],
(crc.amount() >> 0) as u8,
crc.amount() as u8,
(crc.amount() >> 8) as u8,
(crc.amount() >> 16) as u8,
(crc.amount() >> 24) as u8,
Expand Down Expand Up @@ -117,11 +117,11 @@ impl<R> GzEncoder<R> {

#[inline]
fn finish(buf: &[u8; 8]) -> (u32, u32) {
let crc = ((buf[0] as u32) << 0)
let crc = (buf[0] as u32)
| ((buf[1] as u32) << 8)
| ((buf[2] as u32) << 16)
| ((buf[3] as u32) << 24);
let amt = ((buf[4] as u32) << 0)
let amt = (buf[4] as u32)
| ((buf[5] as u32) << 8)
| ((buf[6] as u32) << 16)
| ((buf[7] as u32) << 24);
Expand Down
4 changes: 2 additions & 2 deletions src/gz/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl GzHeaderParser {
if self.flags & FRESERVED != 0 {
return Err(bad_header());
}
self.header.mtime = ((buffer[4] as u32) << 0)
self.header.mtime = (buffer[4] as u32)
| ((buffer[5] as u32) << 8)
| ((buffer[6] as u32) << 16)
| ((buffer[7] as u32) << 24);
Expand Down Expand Up @@ -417,7 +417,7 @@ impl GzBuilder {
header[1] = 0x8b;
header[2] = 8;
header[3] = flg;
header[4] = (mtime >> 0) as u8;
header[4] = mtime as u8;
header[5] = (mtime >> 8) as u8;
header[6] = (mtime >> 16) as u8;
header[7] = (mtime >> 24) as u8;
Expand Down
8 changes: 4 additions & 4 deletions src/gz/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ impl<W: Write> GzEncoder<W> {
while self.crc_bytes_written < 8 {
let (sum, amt) = (self.crc.sum(), self.crc.amount());
let buf = [
(sum >> 0) as u8,
sum as u8,
(sum >> 8) as u8,
(sum >> 16) as u8,
(sum >> 24) as u8,
(amt >> 0) as u8,
amt as u8,
(amt >> 8) as u8,
(amt >> 16) as u8,
(amt >> 24) as u8,
Expand Down Expand Up @@ -294,11 +294,11 @@ impl<W: Write> GzDecoder<W> {
return Err(corrupt());
}

let crc = ((self.crc_bytes[0] as u32) << 0)
let crc = (self.crc_bytes[0] as u32)
| ((self.crc_bytes[1] as u32) << 8)
| ((self.crc_bytes[2] as u32) << 16)
| ((self.crc_bytes[3] as u32) << 24);
let amt = ((self.crc_bytes[4] as u32) << 0)
let amt = (self.crc_bytes[4] as u32)
| ((self.crc_bytes[5] as u32) << 8)
| ((self.crc_bytes[6] as u32) << 16)
| ((self.crc_bytes[7] as u32) << 24);
Expand Down
4 changes: 4 additions & 0 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct Decompress {
/// in-memory data.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
#[allow(clippy::unnecessary_cast)]
pub enum FlushCompress {
/// A typical parameter for passing to compression/decompression functions,
/// this indicates that the underlying stream to decide how much data to
Expand Down Expand Up @@ -86,6 +87,7 @@ pub enum FlushCompress {
/// decompressing in-memory data.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[non_exhaustive]
#[allow(clippy::unnecessary_cast)]
pub enum FlushDecompress {
/// A typical parameter for passing to compression/decompression functions,
/// this indicates that the underlying stream to decide how much data to
Expand Down Expand Up @@ -277,6 +279,7 @@ impl Compress {

match rc {
ffi::MZ_STREAM_ERROR => compress_failed(self.inner.inner.msg()),
#[allow(clippy::unnecessary_cast)]
ffi::MZ_OK => Ok(unsafe { (*stream).adler } as u32),
c => panic!("unknown return code: {}", c),
}
Expand Down Expand Up @@ -493,6 +496,7 @@ impl Decompress {
ffi::inflateSetDictionary(stream, dictionary.as_ptr(), dictionary.len() as ffi::uInt)
};

#[allow(clippy::unnecessary_cast)]
match rc {
ffi::MZ_STREAM_ERROR => decompress_failed(self.inner.inner.msg()),
ffi::MZ_DATA_ERROR => decompress_need_dict(unsafe { (*stream).adler } as u32),
Expand Down