diff --git a/benches/bench.rs b/benches/bench.rs index c71e9fa2..ceb2f220 100755 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -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 { diff --git a/clippy.toml b/clippy.toml index 65eedab9..3a3c07ca 100755 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.40.0" +msrv = "1.50.0" diff --git a/miniz_oxide/src/deflate/core.rs b/miniz_oxide/src/deflate/core.rs index b0a532dc..30762b3f 100644 --- a/miniz_oxide/src/deflate/core.rs +++ b/miniz_oxide/src/deflate/core.rs @@ -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] diff --git a/miniz_oxide/src/inflate/core.rs b/miniz_oxide/src/inflate/core.rs index b53ddde7..ce9540f7 100644 --- a/miniz_oxide/src/inflate/core.rs +++ b/miniz_oxide/src/inflate/core.rs @@ -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] @@ -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; } } diff --git a/miniz_oxide/tests/test.rs b/miniz_oxide/tests/test.rs index 8f447a86..dcb93874 100644 --- a/miniz_oxide/tests/test.rs +++ b/miniz_oxide/tests/test.rs @@ -58,7 +58,7 @@ fn get_test_data() -> Vec { 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(), @@ -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] @@ -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 + ) + }, ); } diff --git a/src/lib.rs b/src/lib.rs index e7b96c39..438fddb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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( diff --git a/src/lib_oxide.rs b/src/lib_oxide.rs index 6473d5a5..ae5b062a 100644 --- a/src/lib_oxide.rs +++ b/src/lib_oxide.rs @@ -193,7 +193,7 @@ pub fn mz_deflate_oxide(stream_oxide: &mut StreamOxide, 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 @@ -264,7 +264,7 @@ pub fn mz_inflate_oxide(stream_oxide: &mut StreamOxide, 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 diff --git a/src/tdef.rs b/src/tdef.rs index ef42d0af..1898fbd7 100644 --- a/src/tdef.rs +++ b/src/tdef.rs @@ -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, pub(crate) callback: Option, } -impl Default for Compressor { - fn default() -> Self { - Compressor { - inner: None, - callback: None, - } - } -} - #[repr(C)] #[allow(bad_style)] #[derive(PartialEq, Eq)] @@ -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 { @@ -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!"); @@ -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( diff --git a/src/tinfl.rs b/src/tinfl.rs index 69433193..befe9580 100755 --- a/src/tinfl.rs +++ b/src/tinfl.rs @@ -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::::new(tinfl_decompressor::default())) + Box::into_raw(Box::default()) } /// Deallocate the compressor. (Does nothing if the argument is null). /// diff --git a/tests/test.rs b/tests/test.rs index 1b63f2bf..f21162fd 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -25,14 +25,14 @@ fn get_test_data() -> Vec { 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); } @@ -40,14 +40,14 @@ fn roundtrip() { 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); }