Skip to content

Commit

Permalink
Latest clippy has spoken!
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ariel-miculas committed Oct 4, 2024
1 parent a62c2b0 commit 1db9958
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
6 changes: 3 additions & 3 deletions puzzlefs-lib/src/compression/zstd_seekable_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R: Seek + Read> Decompressor for ZstdDecompressor<'_, R> {
fn get_uncompressed_length(&mut self) -> io::Result<u64> {
Ok(self.uncompressed_length)
}
}

impl<'a, R: Seek + Read> Seek for ZstdDecompressor<'a, R> {
impl<R: Seek + Read> Seek for ZstdDecompressor<'_, R> {
fn seek(&mut self, offset: io::SeekFrom) -> io::Result<u64> {
match offset {
io::SeekFrom::Start(s) => {
Expand All @@ -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<R: Seek + Read> Read for ZstdDecompressor<'_, R> {
fn read(&mut self, out: &mut [u8]) -> io::Result<usize> {
// 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
Expand Down
2 changes: 1 addition & 1 deletion puzzlefs-lib/src/format/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions puzzlefs-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
6 changes: 1 addition & 5 deletions puzzlefs-lib/src/reader/puzzlefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion puzzlefs-lib/src/reader/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'a> WalkPuzzleFS<'a> {
}
}

impl<'a> Iterator for WalkPuzzleFS<'a> {
impl Iterator for WalkPuzzleFS<'_> {
type Item = Result<DirEntry>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down

0 comments on commit 1db9958

Please sign in to comment.