diff rust/hg-core/src/revlog/index.rs @ 49930:e98fd81bb151

rust-clippy: fix most warnings in `hg-core` All of these are simple changes that for the most part are clear improvements and the rest are at most equivalent. The remaining warnings have to be fixed either with a bigger refactor like for the nested "revlog" module, or in the dependency `bytes-cast`, which we own. This will be done sometime in the future.
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 09 Jan 2023 19:18:43 +0100
parents 0780371d6b1e
children 1928b770e3e7
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/index.rs	Mon Jan 09 19:14:14 2023 +0100
+++ b/rust/hg-core/src/revlog/index.rs	Mon Jan 09 19:18:43 2023 +0100
@@ -21,11 +21,11 @@
 impl IndexHeaderFlags {
     /// Corresponds to FLAG_INLINE_DATA in python
     pub fn is_inline(self) -> bool {
-        return self.flags & 1 != 0;
+        self.flags & 1 != 0
     }
     /// Corresponds to FLAG_GENERALDELTA in python
     pub fn uses_generaldelta(self) -> bool {
-        return self.flags & 2 != 0;
+        self.flags & 2 != 0
     }
 }
 
@@ -35,9 +35,9 @@
     fn format_flags(&self) -> IndexHeaderFlags {
         // No "unknown flags" check here, unlike in python. Maybe there should
         // be.
-        return IndexHeaderFlags {
+        IndexHeaderFlags {
             flags: BigEndian::read_u16(&self.header_bytes[0..2]),
-        };
+        }
     }
 
     /// The only revlog version currently supported by rhg.
@@ -45,7 +45,7 @@
 
     /// Corresponds to `_format_version` in Python.
     fn format_version(&self) -> u16 {
-        return BigEndian::read_u16(&self.header_bytes[2..4]);
+        BigEndian::read_u16(&self.header_bytes[2..4])
     }
 
     const EMPTY_INDEX_HEADER: IndexHeader = IndexHeader {
@@ -59,7 +59,7 @@
     };
 
     fn parse(index_bytes: &[u8]) -> Result<IndexHeader, HgError> {
-        if index_bytes.len() == 0 {
+        if index_bytes.is_empty() {
             return Ok(IndexHeader::EMPTY_INDEX_HEADER);
         }
         if index_bytes.len() < 4 {
@@ -67,13 +67,13 @@
                 "corrupted revlog: can't read the index format header",
             ));
         }
-        return Ok(IndexHeader {
+        Ok(IndexHeader {
             header_bytes: {
                 let bytes: [u8; 4] =
                     index_bytes[0..4].try_into().expect("impossible");
                 bytes
             },
-        });
+        })
     }
 }
 
@@ -127,8 +127,7 @@
                     uses_generaldelta,
                 })
             } else {
-                Err(HgError::corrupted("unexpected inline revlog length")
-                    .into())
+                Err(HgError::corrupted("unexpected inline revlog length"))
             }
         } else {
             Ok(Self {
@@ -466,8 +465,8 @@
             .with_inline(false)
             .build();
 
-        assert_eq!(is_inline(&bytes), false);
-        assert_eq!(uses_generaldelta(&bytes), false);
+        assert!(!is_inline(&bytes));
+        assert!(!uses_generaldelta(&bytes));
     }
 
     #[test]
@@ -478,8 +477,8 @@
             .with_inline(true)
             .build();
 
-        assert_eq!(is_inline(&bytes), true);
-        assert_eq!(uses_generaldelta(&bytes), false);
+        assert!(is_inline(&bytes));
+        assert!(!uses_generaldelta(&bytes));
     }
 
     #[test]
@@ -490,8 +489,8 @@
             .with_inline(true)
             .build();
 
-        assert_eq!(is_inline(&bytes), true);
-        assert_eq!(uses_generaldelta(&bytes), true);
+        assert!(is_inline(&bytes));
+        assert!(uses_generaldelta(&bytes));
     }
 
     #[test]