treewide: fix clippy lints

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I411be69ff31f9cb39cd4cdebc8985b366a6a6964
This commit is contained in:
raf 2026-04-21 18:08:41 +03:00
commit 61ced09d25
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
43 changed files with 558 additions and 464 deletions

View file

@ -45,35 +45,14 @@ fn is_semver_prerelease(s: &str) -> bool {
/// Decompose a version string into its component parts
fn decompose(str_in: &str) -> VecDeque<SortingType> {
if str_in.is_empty() {
return VecDeque::new();
}
// Strip build metadata (after `+`)
let s = if let Some((left, _)) = str_in.split_once('+') {
left
} else {
str_in
};
let mut out: VecDeque<SortingType> = VecDeque::new();
let mut current = String::new();
let mut currently_numeric = s.starts_with(|c: char| c.is_ascii_digit());
let mut skip = s.starts_with('-');
use SortingType::{Lexical, Numerical, SemverPrerelease};
fn handle_split(
current: &str,
c: Option<&char>,
currently_numeric: bool,
) -> Option<SortingType> {
let numeric = if let Some(c) = c {
c.is_ascii_digit()
} else {
false
};
use SortingType::{Lexical, Numerical, SemverPrerelease};
let numeric = c.is_some_and(char::is_ascii_digit);
if currently_numeric {
if numeric {
@ -101,6 +80,23 @@ fn decompose(str_in: &str) -> VecDeque<SortingType> {
}
}
if str_in.is_empty() {
return VecDeque::new();
}
// Strip build metadata (after `+`)
let s = if let Some((left, _)) = str_in.split_once('+') {
left
} else {
str_in
};
let mut out: VecDeque<SortingType> = VecDeque::new();
let mut current = String::new();
let mut currently_numeric = s.starts_with(|c: char| c.is_ascii_digit());
let mut skip = s.starts_with('-');
for c in s.chars() {
if let Some(part) = handle_split(&current, Some(&c), currently_numeric) {
if skip {
@ -131,6 +127,10 @@ fn decompose(str_in: &str) -> VecDeque<SortingType> {
/// This matches the behavior of flexver-java:
/// - "1.0.0" > "1.0.0-beta" (release > pre-release)
/// - "1.0.0-beta" < "1.0.0+build123" (pre-release < build metadata)
#[expect(
clippy::unreachable,
reason = "the VersionComparisonIterator never yields (None, None)"
)]
pub fn compare(left: &str, right: &str) -> Ordering {
let iter = VersionComparisonIterator {
left: decompose(left),

View file

@ -15,7 +15,7 @@ pub fn hash_to_hex(hash: impl AsRef<[u8]>) -> String {
let bytes = hash.as_ref();
let mut hex = String::with_capacity(bytes.len() * 2);
for byte in bytes {
write!(hex, "{byte:02x}").unwrap();
let _ = write!(hex, "{byte:02x}");
}
hex
}
@ -99,7 +99,7 @@ pub fn compute_md5<P: AsRef<Path>>(path: P) -> Result<String> {
let hash = hasher.finalize();
let mut hex = String::with_capacity(hash.len() * 2);
for byte in hash {
std::fmt::write(&mut hex, format_args!("{byte:02x}")).unwrap();
let _ = std::fmt::write(&mut hex, format_args!("{byte:02x}"));
}
Ok(hex)
}