changeset 51766:ec7171748350

rust: apply clippy lints They are at most harmless and at best make the codebase more readable and simpler.
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 18 Jul 2024 13:35:39 +0200
parents 541292a02e09
children 3131445a831b
files rust/hg-core/src/dirstate_tree/dirstate_map.rs rust/hg-core/src/dirstate_tree/on_disk.rs rust/hg-core/src/matchers.rs rust/hg-core/src/revlog/changelog.rs rust/hg-core/src/revlog/index.rs rust/hg-core/src/revlog/node.rs rust/hg-core/tests/test_missing_ancestors.rs
diffstat 7 files changed, 24 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Tue Jul 23 14:25:23 2024 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Thu Jul 18 13:35:39 2024 +0200
@@ -427,19 +427,14 @@
     pub(super) tracked_descendants_count: u32,
 }
 
-#[derive(Debug)]
+#[derive(Debug, Default)]
 pub(super) enum NodeData {
     Entry(DirstateEntry),
     CachedDirectory { mtime: TruncatedTimestamp },
+    #[default]
     None,
 }
 
-impl Default for NodeData {
-    fn default() -> Self {
-        NodeData::None
-    }
-}
-
 impl NodeData {
     fn has_entry(&self) -> bool {
         matches!(self, NodeData::Entry(_))
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs	Tue Jul 23 14:25:23 2024 +0200
+++ b/rust/hg-core/src/dirstate_tree/on_disk.rs	Thu Jul 18 13:35:39 2024 +0200
@@ -332,9 +332,7 @@
     ) -> Result<usize, DirstateV2ParseError> {
         let start = self.base_name_start.get();
         if start < self.full_path.len.get() {
-            let start = usize::try_from(start)
-                // u32 -> usize, could only panic on a 16-bit CPU
-                .expect("dirstate-v2 base_name_start out of bounds");
+            let start = usize::from(start);
             Ok(start)
         } else {
             Err(DirstateV2ParseError::new("not enough bytes for base name"))
@@ -593,8 +591,8 @@
 {
     // Either `usize::MAX` would result in "out of bounds" error since a single
     // `&[u8]` cannot occupy the entire addess space.
-    let start = start.get().try_into().unwrap_or(std::usize::MAX);
-    let len = len.try_into().unwrap_or(std::usize::MAX);
+    let start = start.get().try_into().unwrap_or(usize::MAX);
+    let len = len.try_into().unwrap_or(usize::MAX);
     let bytes = match on_disk.get(start..) {
         Some(bytes) => bytes,
         None => {
--- a/rust/hg-core/src/matchers.rs	Tue Jul 23 14:25:23 2024 +0200
+++ b/rust/hg-core/src/matchers.rs	Thu Jul 18 13:35:39 2024 +0200
@@ -617,7 +617,11 @@
                 std::mem::swap(&mut m1, &mut m2);
             }
             m1.file_set().map(|m1_files| {
-                m1_files.iter().cloned().filter(|f| m2.matches(f)).collect()
+                m1_files
+                    .iter()
+                    .filter(|&f| m2.matches(f))
+                    .cloned()
+                    .collect()
             })
         } else {
             // without exact input file sets, we can't do an exact
@@ -710,7 +714,7 @@
         };
         if base_is_exact {
             new.files = base_files.map(|files| {
-                files.iter().cloned().filter(|f| new.matches(f)).collect()
+                files.iter().filter(|&f| new.matches(f)).cloned().collect()
             });
         }
         new
--- a/rust/hg-core/src/revlog/changelog.rs	Tue Jul 23 14:25:23 2024 +0200
+++ b/rust/hg-core/src/revlog/changelog.rs	Thu Jul 18 13:35:39 2024 +0200
@@ -617,7 +617,7 @@
     #[test]
     fn test_unescape_nul_followed_by_octal() {
         // Escaped NUL chars followed by octal digits are decoded correctly.
-        let expected = b"\012";
+        let expected = b"\x0012";
         let escaped = br"\012";
         let unescaped = unescape_extra(escaped);
         assert_eq!(&expected[..], &unescaped[..]);
@@ -713,7 +713,7 @@
 
         for (extra, msg) in test_cases {
             assert!(
-                decode_extra(&extra).is_err(),
+                decode_extra(extra).is_err(),
                 "corrupt extra should have failed to parse: {}",
                 msg
             );
--- a/rust/hg-core/src/revlog/index.rs	Tue Jul 23 14:25:23 2024 +0200
+++ b/rust/hg-core/src/revlog/index.rs	Thu Jul 18 13:35:39 2024 +0200
@@ -1387,6 +1387,7 @@
     fn vec_of_empty(sets_size: usize, vec_len: usize) -> Vec<Self>;
 
     /// The size of the bit mask in memory
+    #[allow(unused)]
     fn size(&self) -> usize;
 
     /// The number of elements that can be represented in the set.
@@ -1394,12 +1395,14 @@
     /// Another way to put it is that it is the highest integer `C` such that
     /// the set is guaranteed to always be a subset of the integer range
     /// `[0, C)`
+    #[allow(unused)]
     fn capacity(&self) -> usize;
 
     /// Declare `n` to belong to the set
     fn add(&mut self, n: usize);
 
     /// Declare `n` not to belong to the set
+    #[allow(unused)]
     fn discard(&mut self, n: usize);
 
     /// Replace this bit set by its union with other
@@ -1749,6 +1752,9 @@
 }
 
 #[cfg(test)]
+pub use tests::IndexEntryBuilder;
+
+#[cfg(test)]
 mod tests {
     use super::*;
     use crate::node::NULL_NODE;
@@ -2027,6 +2033,3 @@
         assert_eq!(get_version(&bytes), 2)
     }
 }
-
-#[cfg(test)]
-pub use tests::IndexEntryBuilder;
--- a/rust/hg-core/src/revlog/node.rs	Tue Jul 23 14:25:23 2024 +0200
+++ b/rust/hg-core/src/revlog/node.rs	Thu Jul 18 13:35:39 2024 +0200
@@ -83,7 +83,7 @@
     #[inline]
     fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error> {
         match Node::from_bytes(bytes) {
-            Ok((node, rest)) if rest.is_empty() => Ok(node),
+            Ok((node, [])) => Ok(node),
             _ => Err(()),
         }
     }
@@ -323,6 +323,9 @@
 }
 
 #[cfg(test)]
+pub use tests::hex_pad_right;
+
+#[cfg(test)]
 mod tests {
     use super::*;
 
@@ -428,6 +431,3 @@
         assert_eq!(prefix.first_different_nybble(&node), None);
     }
 }
-
-#[cfg(test)]
-pub use tests::hex_pad_right;
--- a/rust/hg-core/tests/test_missing_ancestors.rs	Tue Jul 23 14:25:23 2024 +0200
+++ b/rust/hg-core/tests/test_missing_ancestors.rs	Thu Jul 18 13:35:39 2024 +0200
@@ -69,6 +69,7 @@
     ancs
 }
 
+#[allow(unused)]  // Useful when debugging
 #[derive(Clone, Debug)]
 enum MissingAncestorsAction {
     InitialBases(HashSet<Revision>),