Skip to content

Commit

Permalink
Fix clippy lints (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored May 17, 2024
1 parent 35c71e1 commit 7c758d4
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 50 deletions.
2 changes: 1 addition & 1 deletion benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ops::Drop for HeapBuf {

/// Wrap pointer in a buffer that frees the memory on exit.
fn w(buf: *mut c_void) -> HeapBuf {
HeapBuf { buf: buf }
HeapBuf { buf }
}

fn get_test_file_data(name: &str) -> Vec<u8> {
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.40.0"
msrv = "1.50.0"
4 changes: 2 additions & 2 deletions miniz_oxide/src/deflate/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2392,8 +2392,8 @@ mod test {

#[test]
fn u16_from_slice() {
let mut slice = [208, 7];
assert_eq!(read_u16_le(&mut slice, 0), 2000);
let slice = [208, 7];
assert_eq!(read_u16_le(&slice, 0), 2000);
}

#[test]
Expand Down
38 changes: 19 additions & 19 deletions miniz_oxide/src/inflate/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,19 @@ enum State {

impl State {
fn is_failure(self) -> bool {
match self {
BlockTypeUnexpected => true,
BadCodeSizeSum => true,
BadDistOrLiteralTableLength => true,
BadTotalSymbols => true,
BadZlibHeader => true,
DistanceOutOfBounds => true,
BadRawLength => true,
BadCodeSizeDistPrevLookup => true,
InvalidLitlen => true,
InvalidDist => true,
_ => false,
}
matches!(
self,
BlockTypeUnexpected
| BadCodeSizeSum
| BadDistOrLiteralTableLength
| BadTotalSymbols
| BadZlibHeader
| DistanceOutOfBounds
| BadRawLength
| BadCodeSizeDistPrevLookup
| InvalidLitlen
| InvalidDist
)
}

#[inline]
Expand Down Expand Up @@ -625,15 +625,15 @@ where
// Clippy gives a false positive warning here due to the closure.
// Read enough bytes from the input iterator to cover the number of bits we want.
while l.num_bits < amount {
match read_byte(in_iter, flags, |byte| {
let action = read_byte(in_iter, flags, |byte| {
l.bit_buf |= BitBuffer::from(byte) << l.num_bits;
l.num_bits += 8;
Action::None
}) {
Action::None => (),
// If there are not enough bytes in the input iterator, return and signal that we need
// more.
action => return action,
});

// If there are not enough bytes in the input iterator, return and signal that we need more.
if !matches!(action, Action::None) {
return action;
}
}

Expand Down
17 changes: 9 additions & 8 deletions miniz_oxide/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn get_test_data() -> Vec<u8> {

fn roundtrip(level: u8) {
let data = get_test_data();
let enc = compress_to_vec(&data.as_slice()[..], level);
let enc = compress_to_vec(data.as_slice(), level);
println!(
"Input len: {}, compressed len: {}, level: {}",
data.len(),
Expand Down Expand Up @@ -160,7 +160,7 @@ fn issue_75_empty_input_infinite_loop() {
assert_eq!(d.len(), 0);
let c = miniz_oxide::deflate::compress_to_vec(&[0], 6);
let d = miniz_oxide::inflate::decompress_to_vec(&c).expect("decompression failed!");
assert!(&d == &[0]);
assert!(d == [0]);
}

#[test]
Expand Down Expand Up @@ -202,12 +202,13 @@ fn issue_119_inflate_with_exact_limit() {
.expect("test is not valid, data must correctly decompress when not limited")
.len();

let _ = decompress_to_vec_zlib_with_limit(compressed_data, decompressed_size).expect(
format!(
"data decompression failed when limited to {}",
decompressed_size
)
.as_str(),
let _ = decompress_to_vec_zlib_with_limit(compressed_data, decompressed_size).unwrap_or_else(
|_| {
panic!(
"data decompression failed when limited to {}",
decompressed_size
)
},
);
}

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! [flate2](https://crates.io/crates/flate2) crate.
//!
//! The C API is in a bit of a rough shape currently.
#![allow(clippy::missing_safety_doc)]

extern crate crc32fast;
#[cfg(not(any(
Expand Down
4 changes: 2 additions & 2 deletions src/lib_oxide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn mz_deflate_oxide(stream_oxide: &mut StreamOxide<Compressor>, flush: i32)
};

*next_in = &next_in[ret.bytes_consumed as usize..];
*next_out = &mut mem::replace(next_out, &mut [])[ret.bytes_written as usize..];
*next_out = &mut mem::take(next_out)[ret.bytes_written as usize..];
// Wrapping add to emulate miniz_behaviour, will wrap around >4 GiB on 32-bit.
stream_oxide.total_in = stream_oxide
.total_in
Expand Down Expand Up @@ -264,7 +264,7 @@ pub fn mz_inflate_oxide(stream_oxide: &mut StreamOxide<InflateState>, flush: i32
let flush = MZFlush::new(flush)?;
let ret = inflate(state, next_in, next_out, flush);
*next_in = &next_in[ret.bytes_consumed as usize..];
*next_out = &mut mem::replace(next_out, &mut [])[ret.bytes_written as usize..];
*next_out = &mut mem::take(next_out)[ret.bytes_written as usize..];
// Wrapping add to emulate miniz_behaviour, will wrap around >4 GiB on 32-bit.
stream_oxide.total_in = stream_oxide
.total_in
Expand Down
18 changes: 6 additions & 12 deletions src/tdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ pub struct CallbackFunc {

/// Main compression struct. Not the same as `CompressorOxide`
/// #[repr(C)]
#[derive(Default)]
pub struct Compressor {
pub(crate) inner: Option<CompressorOxide>,
pub(crate) callback: Option<CallbackFunc>,
}

impl Default for Compressor {
fn default() -> Self {
Compressor {
inner: None,
callback: None,
}
}
}

#[repr(C)]
#[allow(bad_style)]
#[derive(PartialEq, Eq)]
Expand Down Expand Up @@ -279,7 +271,7 @@ unmangle!(
flags: c_int,
) -> tdefl_status {
if let Some(d) = d {
match catch_unwind(AssertUnwindSafe(|| {
let panic_res = catch_unwind(AssertUnwindSafe(|| {
d.inner = Some(CompressorOxide::new(flags as u32));
if let Some(f) = put_buf_func {
d.callback = Some(CallbackFunc {
Expand All @@ -289,7 +281,9 @@ unmangle!(
} else {
d.callback = None;
};
})) {
}));

match panic_res {
Ok(_) => tdefl_status::TDEFL_STATUS_OKAY,
Err(_) => {
eprintln!("FATAL ERROR: Caught panic when initializing the compressor!");
Expand All @@ -310,7 +304,7 @@ unmangle!(
}

pub unsafe extern "C" fn tdefl_get_adler32(d: Option<&mut Compressor>) -> c_uint {
d.map_or(crate::MZ_ADLER32_INIT as u32, |d| d.adler32())
d.map_or(crate::MZ_ADLER32_INIT, |d| d.adler32())
}

pub unsafe extern "C" fn tdefl_compress_mem_to_output(
Expand Down
2 changes: 1 addition & 1 deletion src/tinfl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ unmangle!(
/// This does initialize the struct, but not the inner constructor,
/// tdefl_init has to be called before doing anything with it.
pub unsafe extern "C" fn tinfl_decompressor_alloc() -> *mut tinfl_decompressor {
Box::into_raw(Box::<tinfl_decompressor>::new(tinfl_decompressor::default()))
Box::into_raw(Box::default())
}
/// Deallocate the compressor. (Does nothing if the argument is null).
///
Expand Down
8 changes: 4 additions & 4 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ fn get_test_data() -> Vec<u8> {
fn roundtrip() {
let level = 9;
let data = get_test_data();
let enc = compress_to_vec(&data.as_slice()[..], level);
let enc = compress_to_vec(&data, level);
println!(
"Input len: {}, compressed len: {}, level: {}",
data.len(),
enc.len(),
level
);
let dec = decompress_to_vec(enc.as_slice()).unwrap();
let dec = decompress_to_vec(&enc).unwrap();
assert!(data == dec);
}

#[test]
fn roundtrip_level_1() {
let level = 1;
let data = get_test_data();
let enc = compress_to_vec(&data.as_slice()[..], level);
let enc = compress_to_vec(&data, level);
println!(
"Input len: {}, compressed len: {}, level: {}",
data.len(),
enc.len(),
level
);
let dec = decompress_to_vec(enc.as_slice()).unwrap();
let dec = decompress_to_vec(&enc).unwrap();
assert!(data == dec);
}

Expand Down

0 comments on commit 7c758d4

Please sign in to comment.