Mercurial > hg
changeset 51693:918ceb5a3d25
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 | 771598067be2 |
children | ba1b1038a5cf |
files | 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 |
diffstat | 5 files changed, 20 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/on_disk.rs Thu Jul 18 12:38:26 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 Thu Jul 18 12:38:26 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 Thu Jul 18 12:38:26 2024 +0200 +++ b/rust/hg-core/src/revlog/changelog.rs Thu Jul 18 13:35:39 2024 +0200 @@ -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 Thu Jul 18 12:38:26 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 Thu Jul 18 12:38:26 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;