From 1db9958bb18ccab9727dad227cf62d0c6a5b5a7c Mon Sep 17 00:00:00 2001 From: Ariel Miculas-Trif Date: Thu, 3 Oct 2024 23:17:22 +0300 Subject: [PATCH] Latest clippy has spoken! Fix the following errors reported by clippy: ``` error: manual arithmetic check found --> puzzlefs-lib/src/reader/puzzlefs.rs:45:27 | 45 | let addl_offset = if offset > file_offset { | ___________________________^ 46 | | offset - file_offset 47 | | } else { 48 | | 0 49 | | }; | |_________^ help: replace it with: `offset.saturating_sub(file_offset)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub = note: `-D clippy::implicit-saturating-sub` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::implicit_saturating_sub)]` ``` and ignore the needless-lifetimes errors reported on the autogenerated capnp code: ``` | 15 | impl <'a,> ::core::marker::Copy for Reader<'a,> {} | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes = note: `-D clippy::needless-lifetimes` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_lifetimes)]` help: elide the lifetimes | 15 - impl <'a,> ::core::marker::Copy for Reader<'a,> {} 15 + impl ::core::marker::Copy for Reader<'_,> {} | ``` Signed-off-by: Ariel Miculas-Trif --- puzzlefs-lib/src/compression/zstd_seekable_wrapper.rs | 6 +++--- puzzlefs-lib/src/format/types.rs | 2 +- puzzlefs-lib/src/lib.rs | 1 + puzzlefs-lib/src/reader/puzzlefs.rs | 6 +----- puzzlefs-lib/src/reader/walk.rs | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/puzzlefs-lib/src/compression/zstd_seekable_wrapper.rs b/puzzlefs-lib/src/compression/zstd_seekable_wrapper.rs index d2cad25..36ea047 100644 --- a/puzzlefs-lib/src/compression/zstd_seekable_wrapper.rs +++ b/puzzlefs-lib/src/compression/zstd_seekable_wrapper.rs @@ -67,13 +67,13 @@ pub struct ZstdDecompressor<'a, R: Read + Seek> { uncompressed_length: u64, } -impl<'a, R: Seek + Read> Decompressor for ZstdDecompressor<'a, R> { +impl Decompressor for ZstdDecompressor<'_, R> { fn get_uncompressed_length(&mut self) -> io::Result { Ok(self.uncompressed_length) } } -impl<'a, R: Seek + Read> Seek for ZstdDecompressor<'a, R> { +impl Seek for ZstdDecompressor<'_, R> { fn seek(&mut self, offset: io::SeekFrom) -> io::Result { match offset { io::SeekFrom::Start(s) => { @@ -97,7 +97,7 @@ impl<'a, R: Seek + Read> Seek for ZstdDecompressor<'a, R> { } } -impl<'a, R: Seek + Read> Read for ZstdDecompressor<'a, R> { +impl Read for ZstdDecompressor<'_, R> { fn read(&mut self, out: &mut [u8]) -> io::Result { // decompress() gets angry (ZSTD("Corrupted block detected")) if you pass it a buffer // longer than the uncompressable data, so let's be careful to truncate the buffer if it diff --git a/puzzlefs-lib/src/format/types.rs b/puzzlefs-lib/src/format/types.rs index 385c3d8..25fc771 100644 --- a/puzzlefs-lib/src/format/types.rs +++ b/puzzlefs-lib/src/format/types.rs @@ -896,7 +896,7 @@ impl<'de> Deserialize<'de> for Digest { { struct DigestVisitor; - impl<'de> Visitor<'de> for DigestVisitor { + impl Visitor<'_> for DigestVisitor { type Value = Digest; fn expecting(&self, formatter: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { diff --git a/puzzlefs-lib/src/lib.rs b/puzzlefs-lib/src/lib.rs index 80f882b..4c96f88 100644 --- a/puzzlefs-lib/src/lib.rs +++ b/puzzlefs-lib/src/lib.rs @@ -12,6 +12,7 @@ pub mod fsverity_helpers; pub mod oci; pub mod reader; +#[allow(clippy::needless_lifetimes)] pub mod metadata_capnp { include!(concat!(env!("OUT_DIR"), "/metadata_capnp.rs")); } diff --git a/puzzlefs-lib/src/reader/puzzlefs.rs b/puzzlefs-lib/src/reader/puzzlefs.rs index 68b0fa6..048e8c5 100644 --- a/puzzlefs-lib/src/reader/puzzlefs.rs +++ b/puzzlefs-lib/src/reader/puzzlefs.rs @@ -42,11 +42,7 @@ pub(crate) fn file_read( continue; } - let addl_offset = if offset > file_offset { - offset - file_offset - } else { - 0 - }; + let addl_offset = offset.saturating_sub(file_offset); // ok, need to read this chunk; how much? let left_in_buf = data.len() - buf_offset; diff --git a/puzzlefs-lib/src/reader/walk.rs b/puzzlefs-lib/src/reader/walk.rs index 008706f..8ff1376 100644 --- a/puzzlefs-lib/src/reader/walk.rs +++ b/puzzlefs-lib/src/reader/walk.rs @@ -48,7 +48,7 @@ impl<'a> WalkPuzzleFS<'a> { } } -impl<'a> Iterator for WalkPuzzleFS<'a> { +impl Iterator for WalkPuzzleFS<'_> { type Item = Result; fn next(&mut self) -> Option {