Mercurial > public > mercurial-scm > hg-stable
diff rust/hg-core/src/revlog/path_encode.rs @ 50003: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 | fad504cfc94b |
children | 362fe34702d5 |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/path_encode.rs Mon Jan 09 19:14:14 2023 +0100 +++ b/rust/hg-core/src/revlog/path_encode.rs Mon Jan 09 19:18:43 2023 +0100 @@ -2,6 +2,7 @@ #[derive(PartialEq, Debug)] #[allow(non_camel_case_types)] +#[allow(clippy::upper_case_acronyms)] enum path_state { START, /* first byte of a path component */ A, /* "AUX" */ @@ -27,6 +28,7 @@ /* state machine for dir-encoding */ #[allow(non_camel_case_types)] +#[allow(clippy::upper_case_acronyms)] enum dir_state { DDOT, DH, @@ -61,7 +63,7 @@ } } -fn hexencode<'a>(mut dest: Option<&'a mut [u8]>, destlen: &mut usize, c: u8) { +fn hexencode(mut dest: Option<&mut [u8]>, destlen: &mut usize, c: u8) { let hexdigit = b"0123456789abcdef"; charcopy( rewrap_option(&mut dest), @@ -534,10 +536,7 @@ let last_slash = src.iter().rposition(|b| *b == b'/'); let last_dot: Option<usize> = { let s = last_slash.unwrap_or(0); - src[s..] - .iter() - .rposition(|b| *b == b'.') - .and_then(|i| Some(i + s)) + src[s..].iter().rposition(|b| *b == b'.').map(|i| i + s) }; let mut dest = vec![0; MAXSTOREPATHLEN]; @@ -545,8 +544,8 @@ { let mut first = true; - for slice in src[..last_slash.unwrap_or_else(|| src.len())] - .split(|b| *b == b'/') + for slice in + src[..last_slash.unwrap_or(src.len())].split(|b| *b == b'/') { let slice = &slice[..std::cmp::min(slice.len(), dirprefixlen)]; if destlen + (slice.len() + if first { 0 } else { 1 }) @@ -641,6 +640,6 @@ res } } else { - hash_encode(&path) + hash_encode(path) } }