From 06f9c9a3ee441d103e8a6d543277df4ecbe6c930 Mon Sep 17 00:00:00 2001 From: Pascal Seitz Date: Tue, 19 Mar 2024 10:14:58 +0800 Subject: [PATCH] fix nightly, clippy --- src/block/compress.rs | 5 ++--- src/block/decompress.rs | 1 + src/block/decompress_safe.rs | 5 +++-- src/block/hashtable.rs | 3 ++- src/block/mod.rs | 1 - src/fastcpy.rs | 1 - src/fastcpy_unsafe.rs | 1 - src/frame/decompress.rs | 5 ++--- src/frame/header.rs | 1 - src/sink.rs | 9 +++++---- src/test_bins/compress_block.rs | 5 +++++ tests/tests.rs | 2 +- 12 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 src/test_bins/compress_block.rs diff --git a/src/block/compress.rs b/src/block/compress.rs index c18474aa..d283d49c 100644 --- a/src/block/compress.rs +++ b/src/block/compress.rs @@ -16,10 +16,9 @@ use crate::sink::Sink; use crate::sink::SliceSink; #[allow(unused_imports)] use alloc::vec; -use alloc::vec::Vec; -#[cfg(feature = "safe-encode")] -use core::convert::TryInto; +#[allow(unused_imports)] +use alloc::vec::Vec; use super::hashtable::HashTable4K; use super::hashtable::HashTable4KU16; diff --git a/src/block/decompress.rs b/src/block/decompress.rs index 62065a9e..fd8eb271 100644 --- a/src/block/decompress.rs +++ b/src/block/decompress.rs @@ -3,6 +3,7 @@ use crate::block::{DecompressError, MINMATCH}; use crate::fastcpy_unsafe; use crate::sink::SliceSink; use crate::sink::{PtrSink, Sink}; +#[allow(unused_imports)] use alloc::vec::Vec; /// Copies data to output_ptr by self-referential copy from start and match_length diff --git a/src/block/decompress_safe.rs b/src/block/decompress_safe.rs index cebe3cbb..fa7c0b34 100644 --- a/src/block/decompress_safe.rs +++ b/src/block/decompress_safe.rs @@ -1,12 +1,13 @@ //! The block decompression algorithm. -use core::convert::TryInto; - use crate::block::DecompressError; use crate::block::MINMATCH; use crate::sink::Sink; use crate::sink::SliceSink; + +#[allow(unused_imports)] use alloc::vec; +#[allow(unused_imports)] use alloc::vec::Vec; /// Read an integer. diff --git a/src/block/hashtable.rs b/src/block/hashtable.rs index 7c29db75..0e40c63d 100644 --- a/src/block/hashtable.rs +++ b/src/block/hashtable.rs @@ -1,5 +1,5 @@ +#[allow(unused_imports)] use alloc::boxed::Box; -use core::convert::TryInto; /// The Hashtable trait used by the compression to store hashed bytes to their position. /// `val` can be maximum the size of the input in bytes. @@ -36,6 +36,7 @@ fn hash5(sequence: usize) -> u32 { pub trait HashTable { fn get_at(&self, pos: usize) -> usize; fn put_at(&mut self, pos: usize, val: usize); + #[allow(dead_code)] fn clear(&mut self); #[inline] #[cfg(target_pointer_width = "64")] diff --git a/src/block/mod.rs b/src/block/mod.rs index 31c52f40..58ab2498 100644 --- a/src/block/mod.rs +++ b/src/block/mod.rs @@ -30,7 +30,6 @@ pub(crate) mod decompress; pub use compress::*; pub use decompress::*; -use core::convert::TryInto; use core::fmt; pub(crate) const WINDOW_SIZE: usize = 64 * 1024; diff --git a/src/fastcpy.rs b/src/fastcpy.rs index 8bbd480c..aec17321 100644 --- a/src/fastcpy.rs +++ b/src/fastcpy.rs @@ -99,7 +99,6 @@ fn double_copy_trick(src: &[u8], dst: &mut [u8]) { #[cfg(test)] mod tests { use super::slice_copy; - use alloc::vec::Vec; use proptest::prelude::*; proptest! { #[test] diff --git a/src/fastcpy_unsafe.rs b/src/fastcpy_unsafe.rs index fb172804..06053230 100644 --- a/src/fastcpy_unsafe.rs +++ b/src/fastcpy_unsafe.rs @@ -116,7 +116,6 @@ fn double_copy_trick(src: *const u8, dst: *mut u8, len: usize #[cfg(test)] mod tests { use super::slice_copy; - use alloc::vec::Vec; use proptest::prelude::*; proptest! { #[test] diff --git a/src/frame/decompress.rs b/src/frame/decompress.rs index 2b495e2a..3a64831c 100644 --- a/src/frame/decompress.rs +++ b/src/frame/decompress.rs @@ -1,5 +1,4 @@ use std::{ - convert::TryInto, fmt, hash::Hasher, io::{self, BufRead, ErrorKind}, @@ -371,7 +370,7 @@ impl io::Read for FrameDecoder { let mut written = 0; loop { match self.fill_buf() { - Ok(b) if b.is_empty() => return Ok(written), + Ok([]) => return Ok(written), Ok(b) => { let s = std::str::from_utf8(b).map_err(|_| { io::Error::new( @@ -394,7 +393,7 @@ impl io::Read for FrameDecoder { let mut written = 0; loop { match self.fill_buf() { - Ok(b) if b.is_empty() => return Ok(written), + Ok([]) => return Ok(written), Ok(b) => { buf.extend_from_slice(b); let len = b.len(); diff --git a/src/frame/header.rs b/src/frame/header.rs index 1513c11c..04e0e6ad 100644 --- a/src/frame/header.rs +++ b/src/frame/header.rs @@ -2,7 +2,6 @@ use twox_hash::XxHash32; use super::Error; use std::{ - convert::TryInto, fmt::Debug, hash::Hasher, io, diff --git a/src/sink.rs b/src/sink.rs index a440a2de..767afd9e 100644 --- a/src/sink.rs +++ b/src/sink.rs @@ -16,10 +16,10 @@ pub fn vec_sink_for_compression( pos: usize, required_capacity: usize, ) -> SliceSink { - return { + { vec.resize(offset + required_capacity, 0); SliceSink::new(&mut vec[offset..], pos) - }; + } } /// Returns a Sink implementation appropriate for outputing up to `required_capacity` @@ -35,10 +35,10 @@ pub fn vec_sink_for_decompression( pos: usize, required_capacity: usize, ) -> SliceSink { - return { + { vec.resize(offset + required_capacity, 0); SliceSink::new(&mut vec[offset..], pos) - }; + } } pub trait Sink { @@ -47,6 +47,7 @@ pub trait Sink { unsafe fn pos_mut_ptr(&mut self) -> *mut u8; /// read byte at position + #[allow(dead_code)] fn byte_at(&mut self, pos: usize) -> u8; /// Pushes a byte to the end of the Sink. diff --git a/src/test_bins/compress_block.rs b/src/test_bins/compress_block.rs new file mode 100644 index 00000000..74af2b87 --- /dev/null +++ b/src/test_bins/compress_block.rs @@ -0,0 +1,5 @@ +fn main() { + use lz4_flex::compress_prepend_size; + let input = "Hello people, what's up?".to_string(); + let _compressed = compress_prepend_size(input.as_bytes()); +} diff --git a/tests/tests.rs b/tests/tests.rs index c2c2dcd9..cacb7ffe 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -3,7 +3,7 @@ #[macro_use] extern crate more_asserts; -use std::{convert::TryInto, iter}; +use std::iter; use lz4_compress::compress as lz4_rust_compress; #[cfg(feature = "frame")]