about summary refs log tree commit diff
diff options
context:
space:
mode:
authorzseri <zseri.devel@ytrizja.de>2021-12-25T01·27+0100
committerzseri <zseri.devel@ytrizja.de>2021-12-25T01·33+0000
commit5f2b37bdb07f5b931ac555939710ce681472e04d (patch)
tree95c4d3ac700747806c279d707b42ceb523f5a939
parent8cdda57580bb1b4fdb19091c45b437f6327d78c0 (diff)
chore(zseri/store-ref-scanner): fix clippy warnings r/3384
Change-Id: I0e75feb501c56a98a73048443c36132308245945
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4597
Tested-by: BuildkiteCI
Reviewed-by: zseri <zseri.devel@ytrizja.de>
-rw-r--r--users/zseri/store-ref-scanner/src/hbm.rs6
-rw-r--r--users/zseri/store-ref-scanner/src/lib.rs17
2 files changed, 6 insertions, 17 deletions
diff --git a/users/zseri/store-ref-scanner/src/hbm.rs b/users/zseri/store-ref-scanner/src/hbm.rs
index 810a0c99cf88..881f1dfdeb75 100644
--- a/users/zseri/store-ref-scanner/src/hbm.rs
+++ b/users/zseri/store-ref-scanner/src/hbm.rs
@@ -1,6 +1,8 @@
 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
 pub struct HalfBytesMask(pub [u8; 16]);
 
+// fires erronously
+#[allow(clippy::zero_prefixed_literal)]
 impl HalfBytesMask {
     pub const B32_REVSHA256: HalfBytesMask =
         HalfBytesMask([0, 0, 0, 0, 0, 0, 255, 3, 0, 0, 0, 0, 222, 127, 207, 7]);
@@ -17,7 +19,7 @@ impl HalfBytesMask {
             let mut tmp = 0;
             let fin = idx * 8;
             macro_rules! bitx {
-            ($($a:expr),+) => {{ $( if x[fin + $a] { tmp += (1 << $a) as u8; } )+ }}
+                ($($a:expr),+) => {{ $( if x[fin + $a] { tmp += (1 << $a) as u8; } )+ }}
             }
             bitx!(0, 1, 2, 3, 4, 5, 6, 7);
             ret[idx] = tmp;
@@ -63,7 +65,7 @@ impl HalfBytesMask {
                 return;
             }
         }
-        let mut block = &mut self.0[usize::from(byte / 8)];
+        let block = &mut self.0[usize::from(byte / 8)];
         let bitpat = (1 << u32::from(byte % 8)) as u8;
         if allow {
             *block |= bitpat;
diff --git a/users/zseri/store-ref-scanner/src/lib.rs b/users/zseri/store-ref-scanner/src/lib.rs
index 2cf94b42ccd7..63b3689978ff 100644
--- a/users/zseri/store-ref-scanner/src/lib.rs
+++ b/users/zseri/store-ref-scanner/src/lib.rs
@@ -1,7 +1,5 @@
 // TODO: make this no_std if possible
 
-use camino::Utf8PathBuf;
-
 mod hbm;
 pub use hbm::HalfBytesMask;
 
@@ -36,7 +34,7 @@ impl ScannerInput for &mut [u8] {
     fn split_to(&mut self, at: usize) -> Self {
         // Lifetime dance taken from `impl Write for &mut [u8]`.
         // Taken from crate `std`.
-        let (a, b) = core::mem::replace(self, &mut []).split_at_mut(at);
+        let (a, b) = std::mem::take(self).split_at_mut(at);
         *self = b;
         a
     }
@@ -55,17 +53,6 @@ pub struct StoreRefScanner<'x, Input: 'x> {
     spec: &'x StoreSpec,
 }
 
-/// Taken from crate `yz-string-utils`.
-fn get_offset_of<T>(whole_buffer: &T, part: &T) -> usize
-where
-    T: AsRef<[u8]> + ?Sized,
-{
-    // NOTE: originally I wanted to use offset_from() here once it's stable,
-    // but according to https://github.com/rust-lang/rust/issues/41079#issuecomment-657163887
-    // this would be UB in cases where the code below isn't.
-    part.as_ref().as_ptr() as usize - whole_buffer.as_ref().as_ptr() as usize
-}
-
 impl<'x, Input> StoreRefScanner<'x, Input>
 where
     Input: ScannerInput + 'x,
@@ -115,7 +102,7 @@ where
                     .skip(hbl)
                     .find(|&(_, &i)| !self.spec.valid_restbytes.contains(i))
                     .map(|(eosp, _)| eosp)
-                    .unwrap_or(core::cmp::min(BASENAME_MAXLEN, self.input.as_ref().len()));
+                    .unwrap_or_else(|| core::cmp::min(BASENAME_MAXLEN, self.input.as_ref().len()));
                 return Some(self.input.split_to(rlen));
             }
         }