From 3dc71b2f5160ef9bd46143eed0edb5d2557b58e6 Mon Sep 17 00:00:00 2001 From: aur-build Date: Sun, 22 Nov 2026 10:36:24 +0000 Subject: rustfmt,lints: pin the formatting, adopt the idiom lints, pay them off rustfmt.toml fixes the shape the tree is written in (120 columns, small items kept on one line) and one canonical pass makes it the truth. [lints.clippy] names the idiom lints worth enforcing and leaves out the two that would add doc-comment boilerplate rather than remove it. The tree pays them off here: write!/writeln! instead of push_str(&format!()), let-else instead of match-on-Option, borrows where a thread entry point only reads what it owns, no `&self` on a Copy state and no `self` nobody reads. ops::to_prometheus gains one gauge helper: a metric's HELP, TYPE and value are now emitted by the same call instead of three. --- src/pkgver/mod.rs | 120 +++++++++++++++++++++++++++--------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) (limited to 'src/pkgver') diff --git a/src/pkgver/mod.rs b/src/pkgver/mod.rs index c97b4a2..5abb5c0 100644 --- a/src/pkgver/mod.rs +++ b/src/pkgver/mod.rs @@ -64,14 +64,7 @@ impl Version { } } -pub fn compare( - epoch_a: i64, - pkgver_a: &str, - pkgrel_a: &str, - epoch_b: i64, - pkgver_b: &str, - pkgrel_b: &str, -) -> Ordering { +pub fn compare(epoch_a: i64, pkgver_a: &str, pkgrel_a: &str, epoch_b: i64, pkgver_b: &str, pkgrel_b: &str) -> Ordering { match epoch_a.cmp(&epoch_b) { Ordering::Equal => {} o => return o, @@ -133,18 +126,10 @@ fn vercmp_string(a: &str, b: &str) -> Ordering { match (i >= a.len(), j >= b.len()) { (true, true) => return Ordering::Equal, (true, false) => { - return if j < b.len() && b[j].is_ascii_alphabetic() { - Ordering::Greater - } else { - Ordering::Less - } + return if j < b.len() && b[j].is_ascii_alphabetic() { Ordering::Greater } else { Ordering::Less } } (false, true) => { - return if i < a.len() && a[i].is_ascii_alphabetic() { - Ordering::Less - } else { - Ordering::Greater - } + return if i < a.len() && a[i].is_ascii_alphabetic() { Ordering::Less } else { Ordering::Greater } } (false, false) => {} } @@ -243,23 +228,13 @@ impl Dep { Some((head, _desc)) if !head.contains(['>', '<', '=']) => head, _ => s, }; - for (tok, op) in [ - (">=", DepOp::Ge), - ("<=", DepOp::Le), - ("=", DepOp::Eq), - (">", DepOp::Gt), - ("<", DepOp::Lt), - ] { + for (tok, op) in [(">=", DepOp::Ge), ("<=", DepOp::Le), ("=", DepOp::Eq), (">", DepOp::Gt), ("<", DepOp::Lt)] { if let Some((name, ver)) = s.split_once(tok) { let name = name.trim(); if name.is_empty() { return None; } - return Some(Dep { - name: name.to_string(), - op, - version: Some(ver.trim().to_string()), - }); + return Some(Dep { name: name.to_string(), op, version: Some(ver.trim().to_string()) }); } } Some(Dep { name: s.trim().to_string(), op: DepOp::Any, version: None }) @@ -368,19 +343,53 @@ mod tests { // --------------------------------------------------------------------- const ORDERED: &[(&str, &str)] = &[ - ("v1.2.3", "v1.2.4"), ("1.0", "1.1"), ("1.1", "1.2"), ("1.2", "2.0"), - ("2.0", "2.1.0"), ("2.1.0", "2.1.1"), ("1.0rc1", "1.0"), ("1.0", "1.0.0"), - ("1.0.0", "1.0.1"), ("1.0.1", "1.1.0"), ("1.1", "1.1.0"), ("1", "1.0"), - ("1.0", "1.0.1"), ("1.0.1", "1.1"), ("1.1", "1.1.1"), ("1.1.1", "1.2"), - ("1.2", "1.2.2"), ("1.2.2", "1.3"), ("1.3", "1.3.1"), ("1.3.1", "1.4"), - ("1.4", "1.4.1"), ("1.4.1", "2.0"), ("2.0", "2.0.1"), ("2.0.1", "2.1.0"), - ("2.1.0", "2.1.1"), ("2.1.1", "3.0"), ("3.0", "3.0.1"), ("3.0.1", "4.0"), - ("1.0.a", "1.0.1"), ("1.0.b", "1.0.2"), ("1.0.2", "1.0.2.a"), - ("1.0.2.a", "1.0.2.aa"), ("1.0.2.aa", "1.0.2.b"), ("1.0.2.b", "1.0.2.bb"), - ("1.0.2.bb", "1.0.3"), ("1.0.3a", "1.0.3b"), ("1.0.3b", "1.1"), - ("1.1a", "1.2"), ("1:0.8", "2:0.1"), ("2:0.1", "3:0.1"), ("1.0-1", "1.0-2"), - ("1.0-2", "1.0-3"), ("1.0-3", "1.1-1"), ("1:1.0-1", "1:1.0-2"), - ("1:1.0-2", "2:0.1-1"), ("2.5", "2.24"), ("2.0", "2.0.01"), + ("v1.2.3", "v1.2.4"), + ("1.0", "1.1"), + ("1.1", "1.2"), + ("1.2", "2.0"), + ("2.0", "2.1.0"), + ("2.1.0", "2.1.1"), + ("1.0rc1", "1.0"), + ("1.0", "1.0.0"), + ("1.0.0", "1.0.1"), + ("1.0.1", "1.1.0"), + ("1.1", "1.1.0"), + ("1", "1.0"), + ("1.0", "1.0.1"), + ("1.0.1", "1.1"), + ("1.1", "1.1.1"), + ("1.1.1", "1.2"), + ("1.2", "1.2.2"), + ("1.2.2", "1.3"), + ("1.3", "1.3.1"), + ("1.3.1", "1.4"), + ("1.4", "1.4.1"), + ("1.4.1", "2.0"), + ("2.0", "2.0.1"), + ("2.0.1", "2.1.0"), + ("2.1.0", "2.1.1"), + ("2.1.1", "3.0"), + ("3.0", "3.0.1"), + ("3.0.1", "4.0"), + ("1.0.a", "1.0.1"), + ("1.0.b", "1.0.2"), + ("1.0.2", "1.0.2.a"), + ("1.0.2.a", "1.0.2.aa"), + ("1.0.2.aa", "1.0.2.b"), + ("1.0.2.b", "1.0.2.bb"), + ("1.0.2.bb", "1.0.3"), + ("1.0.3a", "1.0.3b"), + ("1.0.3b", "1.1"), + ("1.1a", "1.2"), + ("1:0.8", "2:0.1"), + ("2:0.1", "3:0.1"), + ("1.0-1", "1.0-2"), + ("1.0-2", "1.0-3"), + ("1.0-3", "1.1-1"), + ("1:1.0-1", "1:1.0-2"), + ("1:1.0-2", "2:0.1-1"), + ("2.5", "2.24"), + ("2.0", "2.0.01"), ]; #[test] @@ -414,11 +423,7 @@ mod tests { let mut cols = line.split('\t'); let (a, b) = (cols.next().unwrap(), cols.next().unwrap()); let theirs: i32 = cols.next().unwrap().parse().expect("verdict column"); - assert_eq!( - sign(vercmp_string(a, b)), - theirs, - "vercmp({a:?}, {b:?}) disagrees with the recorded oracle" - ); + assert_eq!(sign(vercmp_string(a, b)), theirs, "vercmp({a:?}, {b:?}) disagrees with the recorded oracle"); checked += 1; recorded.insert((a, b), theirs); } @@ -443,10 +448,9 @@ mod tests { return; } let fragments = [ - "1", "1.0", "1.0.0", "1.0.1", "1.1", "2", "2.0", "1.0a", "1.0rc1", "1.0.2a", "1.0.2.1", - "1.0.2.a", "1.0.2.aa", "1.0.2.b", "1.0.2z", "1.0z", "1.0.z", "0.9", "10", "2.24", "2.5", - "1.02", "1.0_2", "1.0.p", "1.0.3a", "1.0.3b", "1.a", "1a", "1.0+git", "1.0~beta", "2.0_1", - "1.0.x", "2024.01", + "1", "1.0", "1.0.0", "1.0.1", "1.1", "2", "2.0", "1.0a", "1.0rc1", "1.0.2a", "1.0.2.1", "1.0.2.a", + "1.0.2.aa", "1.0.2.b", "1.0.2z", "1.0z", "1.0.z", "0.9", "10", "2.24", "2.5", "1.02", "1.0_2", "1.0.p", + "1.0.3a", "1.0.3b", "1.a", "1a", "1.0+git", "1.0~beta", "2.0_1", "1.0.x", "2024.01", ]; let mut checked = 0; for a in fragments { @@ -462,13 +466,9 @@ mod tests { #[test] fn equal_versions_compare_equal_and_leading_zeros_do_not_matter() { - for (a, b) in [ - ("1.0-1", "1.0-1"), - ("1:1.0-1", "1:1.0-1"), - ("1.02-1", "1.2-1"), - ("01.0-1", "1.0-1"), - ("1.0-01", "1.0-1"), - ] { + for (a, b) in + [("1.0-1", "1.0-1"), ("1:1.0-1", "1:1.0-1"), ("1.02-1", "1.2-1"), ("01.0-1", "1.0-1"), ("1.0-01", "1.0-1")] + { assert_eq!(vercmp(a, b), Ordering::Equal, "{a} vs {b}"); } } @@ -537,7 +537,7 @@ mod tests { fn provides_and_conflicts_use_the_same_grammar() { for src in ["aur-build", "aur-build=0.1-1", "virtual-thing>=1.0"] { let d = Dep::parse(src).expect(src); - assert!(!d.name().is_empty()); + assert_ne!(d.name(), ""); assert!(!d.name().contains(['>', '<', '='])); } assert_eq!(dep_names(&["aur-build=0.1-1".into(), "other".into()]), vec!["aur-build", "other"]); -- cgit v1.2.3