From 06632924e81805742605cda313863b04dfaa1879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Iv=C3=A1nek?= Date: Mon, 21 Oct 2024 07:05:49 +0200 Subject: [PATCH] fix: resolve clippy warning in nightly (#252) --- src/read.rs | 26 +++++++++++++------------- src/read/xz.rs | 2 +- src/unstable.rs | 2 +- src/write.rs | 8 ++++---- src/zipcrypto.rs | 3 ++- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/read.rs b/src/read.rs index e8b55107b..354d80702 100644 --- a/src/read.rs +++ b/src/read.rs @@ -132,7 +132,7 @@ pub(crate) enum CryptoReader<'a> { }, } -impl<'a> Read for CryptoReader<'a> { +impl Read for CryptoReader<'_> { fn read(&mut self, buf: &mut [u8]) -> io::Result { match self { CryptoReader::Plaintext(r) => r.read(buf), @@ -201,7 +201,7 @@ pub(crate) enum ZipFileReader<'a> { Compressed(Box>>>>), } -impl<'a> Read for ZipFileReader<'a> { +impl Read for ZipFileReader<'_> { fn read(&mut self, buf: &mut [u8]) -> io::Result { match self { ZipFileReader::NoReader => invalid_state(), @@ -282,7 +282,7 @@ impl<'a, R: Seek> SeekableTake<'a, R> { } } -impl<'a, R: Seek> Seek for SeekableTake<'a, R> { +impl Seek for SeekableTake<'_, R> { fn seek(&mut self, pos: SeekFrom) -> io::Result { let offset = match pos { SeekFrom::Start(offset) => Some(offset), @@ -306,7 +306,7 @@ impl<'a, R: Seek> Seek for SeekableTake<'a, R> { } } -impl<'a, R: Read> Read for SeekableTake<'a, R> { +impl Read for SeekableTake<'_, R> { fn read(&mut self, buf: &mut [u8]) -> io::Result { let written = self .inner @@ -1652,20 +1652,20 @@ impl<'a> ZipFile<'a> { } /// Methods for retrieving information on zip files -impl<'a> ZipFile<'a> { +impl ZipFile<'_> { /// iterate through all extra fields pub fn extra_data_fields(&self) -> impl Iterator { self.data.extra_fields.iter() } } -impl<'a> HasZipMetadata for ZipFile<'a> { +impl HasZipMetadata for ZipFile<'_> { fn get_metadata(&self) -> &ZipFileData { self.data.as_ref() } } -impl<'a> Read for ZipFile<'a> { +impl Read for ZipFile<'_> { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.reader.read(buf) } @@ -1683,7 +1683,7 @@ impl<'a> Read for ZipFile<'a> { } } -impl<'a, R: Read> Read for ZipFileSeek<'a, R> { +impl Read for ZipFileSeek<'_, R> { fn read(&mut self, buf: &mut [u8]) -> io::Result { match &mut self.reader { ZipFileSeekReader::Raw(r) => r.read(buf), @@ -1691,7 +1691,7 @@ impl<'a, R: Read> Read for ZipFileSeek<'a, R> { } } -impl<'a, R: Seek> Seek for ZipFileSeek<'a, R> { +impl Seek for ZipFileSeek<'_, R> { fn seek(&mut self, pos: SeekFrom) -> io::Result { match &mut self.reader { ZipFileSeekReader::Raw(r) => r.seek(pos), @@ -1699,13 +1699,13 @@ impl<'a, R: Seek> Seek for ZipFileSeek<'a, R> { } } -impl<'a, R> HasZipMetadata for ZipFileSeek<'a, R> { +impl HasZipMetadata for ZipFileSeek<'_, R> { fn get_metadata(&self) -> &ZipFileData { self.data.as_ref() } } -impl<'a> Drop for ZipFile<'a> { +impl Drop for ZipFile<'_> { fn drop(&mut self) { // self.data is Owned, this reader is constructed by a streaming reader. // In this case, we want to exhaust the reader so that the next file is accessible. @@ -1734,7 +1734,7 @@ impl<'a> Drop for ZipFile<'a> { /// * `comment`: set to an empty string /// * `data_start`: set to 0 /// * `external_attributes`: `unix_mode()`: will return None -pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult>> { +pub fn read_zipfile_from_stream(reader: &mut R) -> ZipResult>> { // We can't use the typical ::parse() method, as we follow separate code paths depending on the // "magic" value (since the magic value will be from the central directory header if we've // finished iterating over all the actual files). @@ -1758,7 +1758,7 @@ pub fn read_zipfile_from_stream<'a, R: Read>(reader: &'a mut R) -> ZipResult return Err(e), } - let limit_reader = (reader as &'a mut dyn Read).take(result.compressed_size); + let limit_reader = (reader as &mut dyn Read).take(result.compressed_size); let result_crc32 = result.crc32; let result_compression_method = result.compression_method; diff --git a/src/read/xz.rs b/src/read/xz.rs index 991df62b0..f9ed41af2 100644 --- a/src/read/xz.rs +++ b/src/read/xz.rs @@ -59,7 +59,7 @@ struct BufWriter<'a> { rest: &'a mut VecDeque, } -impl<'a> Write for BufWriter<'a> { +impl Write for BufWriter<'_> { fn write(&mut self, buf: &[u8]) -> Result { if self.inner.len() > *self.written { let len = std::cmp::min(buf.len(), self.inner.len() - *self.written); diff --git a/src/unstable.rs b/src/unstable.rs index 81cf18ea5..4bce5a616 100644 --- a/src/unstable.rs +++ b/src/unstable.rs @@ -19,7 +19,7 @@ pub mod write { /// This is not recommended for new archives, as ZipCrypto is not secure. fn with_deprecated_encryption(self, password: &[u8]) -> Self; } - impl<'k, T: FileOptionExtension> FileOptionsExt for FileOptions<'k, T> { + impl FileOptionsExt for FileOptions<'_, T> { fn with_deprecated_encryption(self, password: &[u8]) -> FileOptions<'static, T> { self.with_deprecated_encryption(password) } diff --git a/src/write.rs b/src/write.rs index 48276cb9d..a7c300430 100644 --- a/src/write.rs +++ b/src/write.rs @@ -414,7 +414,7 @@ impl<'a> arbitrary::Arbitrary<'a> for FileOptions<'a, ExtendedFileOptions> { } } -impl<'k, T: FileOptionExtension> FileOptions<'k, T> { +impl FileOptions<'_, T> { /// Set the compression method for the new file /// /// The default is `CompressionMethod::Deflated` if it is enabled. If not, @@ -520,7 +520,7 @@ impl<'k, T: FileOptionExtension> FileOptions<'k, T> { self } } -impl<'k> FileOptions<'k, ExtendedFileOptions> { +impl FileOptions<'_, ExtendedFileOptions> { /// Adds an extra data field. pub fn add_extra_data( &mut self, @@ -544,7 +544,7 @@ impl<'k> FileOptions<'k, ExtendedFileOptions> { self } } -impl<'k, T: FileOptionExtension> Default for FileOptions<'k, T> { +impl Default for FileOptions<'_, T> { /// Construct a new FileOptions object fn default() -> Self { Self { @@ -1235,7 +1235,7 @@ impl ZipWriter { /// Add a new file using the already compressed data from a ZIP file being read and renames it, this /// allows faster copies of the `ZipFile` since there is no need to decompress and compress it again. /// Any `ZipFile` metadata is copied and not checked, for example the file CRC. - + /// /// ```no_run /// use std::fs::File; /// use std::io::{Read, Seek, Write}; diff --git a/src/zipcrypto.rs b/src/zipcrypto.rs index bd81b5c43..b8f51540a 100644 --- a/src/zipcrypto.rs +++ b/src/zipcrypto.rs @@ -27,7 +27,8 @@ impl Debug for ZipCryptoKeys { use std::hash::Hasher; let mut t = DefaultHasher::new(); self.hash(&mut t); - return f.write_fmt(format_args!("ZipCryptoKeys(hash {})", t.finish())); + + f.write_fmt(format_args!("ZipCryptoKeys(hash {})", t.finish())) } #[cfg(any(test, fuzzing))] return f.write_fmt(format_args!(