fix clippy lints

This commit is contained in:
John Turner
2025-11-15 01:55:19 +00:00
parent dfaad015b9
commit 0436fbc770
5 changed files with 44 additions and 45 deletions

View File

@@ -77,7 +77,7 @@ pub struct SlotName(#[get(method = "name", kind = "deref")] String);
#[derive(Clone, Debug, PartialEq, Eq, Get)] #[derive(Clone, Debug, PartialEq, Eq, Get)]
pub struct Slot { pub struct Slot {
slot: Option<SlotName>, primary: Option<SlotName>,
sub: Option<SlotName>, sub: Option<SlotName>,
operator: Option<SlotOperator>, operator: Option<SlotOperator>,
} }
@@ -134,6 +134,7 @@ pub struct Atom {
} }
impl Cpv { impl Cpv {
#[must_use]
pub fn into_cp(self) -> Cp { pub fn into_cp(self) -> Cp {
Cp { Cp {
name: self.name, name: self.name,
@@ -143,13 +144,12 @@ impl Cpv {
} }
impl Atom { impl Atom {
#[must_use]
pub fn version_operator(&self) -> Option<VersionOperator> { pub fn version_operator(&self) -> Option<VersionOperator> {
match self.version { self.version.clone().map(|(oper, _)| oper)
Some((operator, _)) => Some(operator),
None => None,
}
} }
#[must_use]
pub fn into_cp(self) -> Cp { pub fn into_cp(self) -> Cp {
Cp { Cp {
category: self.category, category: self.category,
@@ -157,6 +157,7 @@ impl Atom {
} }
} }
#[must_use]
pub fn into_cpv(self) -> Option<Cpv> { pub fn into_cpv(self) -> Option<Cpv> {
match self.version { match self.version {
Some((_, version)) => Some(Cpv { Some((_, version)) => Some(Cpv {
@@ -177,8 +178,7 @@ impl PartialEq for VersionSuffix {
(Some(a), Some(b)) => a.0 == b.0, (Some(a), Some(b)) => a.0 == b.0,
(Some(a), None) if a.get().chars().all(|c| c == '0') => true, (Some(a), None) if a.get().chars().all(|c| c == '0') => true,
(None, Some(b)) if b.get().chars().all(|c| c == '0') => true, (None, Some(b)) if b.get().chars().all(|c| c == '0') => true,
(Some(_), None) => false, (Some(_), None) | (None, Some(_)) => false,
(None, Some(_)) => false,
(None, None) => true, (None, None) => true,
} }
} }
@@ -220,10 +220,9 @@ impl PartialEq for VersionSuffixes {
loop { loop {
match (a.next(), b.next()) { match (a.next(), b.next()) {
(Some(a), Some(b)) if a == b => continue, (Some(a), Some(b)) if a == b => (),
(Some(_), Some(_)) => break false, (Some(_) | None, Some(_)) | (Some(_), None) => break false,
(None, None) => break true, (None, None) => break true,
_ => break false,
} }
} }
} }
@@ -247,7 +246,7 @@ impl Ord for VersionSuffixes {
(Some(a), Some(b)) => match a.cmp(b) { (Some(a), Some(b)) => match a.cmp(b) {
Ordering::Less => break Ordering::Less, Ordering::Less => break Ordering::Less,
Ordering::Greater => break Ordering::Greater, Ordering::Greater => break Ordering::Greater,
Ordering::Equal => continue, Ordering::Equal => (),
}, },
(Some(a), None) if matches!(a.kind, VersionSuffixKind::P) => { (Some(a), None) if matches!(a.kind, VersionSuffixKind::P) => {
break Ordering::Greater; break Ordering::Greater;
@@ -271,9 +270,9 @@ impl PartialEq for VersionNumbers {
loop { loop {
match (a.next(), b.next()) { match (a.next(), b.next()) {
(Some(a), Some(b)) if a.get().starts_with("0") => { (Some(a), Some(b)) if a.get().starts_with('0') => {
let a = a.get().trim_end_matches("0"); let a = a.get().trim_end_matches('0');
let b = b.get().trim_end_matches("0"); let b = b.get().trim_end_matches('0');
if a != b { if a != b {
break false; break false;
@@ -284,8 +283,8 @@ impl PartialEq for VersionNumbers {
break false; break false;
} }
} }
(Some(a), None) if a.get().chars().all(|c| c == '0') => continue, (Some(a), None) if a.get().chars().all(|c| c == '0') => (),
(None, Some(b)) if b.get().chars().all(|c| c == '0') => continue, (None, Some(b)) if b.get().chars().all(|c| c == '0') => (),
(None, None) => break true, (None, None) => break true,
_ => break false, _ => break false,
} }
@@ -313,8 +312,8 @@ impl Ord for VersionNumbers {
.unwrap() .unwrap()
.cmp(&other.get().first().unwrap().get().parse::<u64>().unwrap()) .cmp(&other.get().first().unwrap().get().parse::<u64>().unwrap())
{ {
Ordering::Less => return Ordering::Less, Ordering::Less => Ordering::Less,
Ordering::Greater => return Ordering::Greater, Ordering::Greater => Ordering::Greater,
Ordering::Equal => { Ordering::Equal => {
let mut a = self.get().iter().skip(1); let mut a = self.get().iter().skip(1);
let mut b = other.get().iter().skip(1); let mut b = other.get().iter().skip(1);
@@ -322,15 +321,15 @@ impl Ord for VersionNumbers {
loop { loop {
match (a.next(), b.next()) { match (a.next(), b.next()) {
(Some(a), Some(b)) (Some(a), Some(b))
if a.get().starts_with("0") || b.get().starts_with("0") => if a.get().starts_with('0') || b.get().starts_with('0') =>
{ {
let a = a.get().trim_end_matches("0"); let a = a.get().trim_end_matches('0');
let b = b.get().trim_end_matches("0"); let b = b.get().trim_end_matches('0');
match a.cmp(b) { match a.cmp(b) {
Ordering::Less => break Ordering::Less, Ordering::Less => break Ordering::Less,
Ordering::Greater => break Ordering::Greater, Ordering::Greater => break Ordering::Greater,
Ordering::Equal => continue, Ordering::Equal => (),
} }
} }
(Some(a), Some(b)) => match a (Some(a), Some(b)) => match a
@@ -341,7 +340,7 @@ impl Ord for VersionNumbers {
{ {
Ordering::Less => break Ordering::Less, Ordering::Less => break Ordering::Less,
Ordering::Greater => break Ordering::Greater, Ordering::Greater => break Ordering::Greater,
Ordering::Equal => continue, Ordering::Equal => (),
}, },
(Some(_), None) => break Ordering::Greater, (Some(_), None) => break Ordering::Greater,
@@ -364,9 +363,8 @@ impl PartialEq for Version {
a.get().parse::<u64>().unwrap() == b.get().parse::<u64>().unwrap() a.get().parse::<u64>().unwrap() == b.get().parse::<u64>().unwrap()
} }
(Some(a), None) if a.get().chars().all(|c| c == '0') => true, (Some(a), None) if a.get().chars().all(|c| c == '0') => true,
(Some(_), None) => false,
(None, Some(b)) if b.get().chars().all(|c| c == '0') => true, (None, Some(b)) if b.get().chars().all(|c| c == '0') => true,
(None, Some(_)) => false, (Some(_), None) | (None, Some(_)) => false,
(None, None) => true, (None, None) => true,
} }
} }
@@ -402,7 +400,7 @@ impl Ord for Version {
(None, Some(_)) => return Ordering::Less, (None, Some(_)) => return Ordering::Less,
(None, None) => (), (None, None) => (),
_ => unreachable!(), _ => unreachable!(),
}; }
match (&self.rev, &other.rev) { match (&self.rev, &other.rev) {
(Some(a), Some(b)) => a (Some(a), Some(b)) => a
@@ -499,7 +497,7 @@ impl fmt::Display for Version {
.numbers .numbers
.get() .get()
.iter() .iter()
.map(|n| n.get()) .map(VersionNumber::get)
.intersperse(".") .intersperse(".")
.collect::<String>(); .collect::<String>();
@@ -507,18 +505,18 @@ impl fmt::Display for Version {
.suffixes .suffixes
.get() .get()
.iter() .iter()
.map(|s| s.to_string()) .map(VersionSuffix::to_string)
.intersperse("_".to_string()) .intersperse("_".to_string())
.collect::<String>(); .collect::<String>();
write!(f, "{}", numbers)?; write!(f, "{numbers}")?;
if let Some(letter) = self.letter { if let Some(letter) = self.letter {
write!(f, "{letter}")?; write!(f, "{letter}")?;
} }
if suffixes.len() > 0 { if !suffixes.is_empty() {
write!(f, "_{}", suffixes)?; write!(f, "_{suffixes}")?;
} }
if let Some(rev) = self.rev.as_ref() { if let Some(rev) = self.rev.as_ref() {
@@ -546,7 +544,7 @@ impl fmt::Display for SlotName {
impl fmt::Display for Slot { impl fmt::Display for Slot {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(slot) = self.slot.as_ref() { if let Some(slot) = self.primary.as_ref() {
write!(f, "{slot}")?; write!(f, "{slot}")?;
} }
@@ -652,7 +650,7 @@ impl fmt::Display for Atom {
let usedeps = self let usedeps = self
.usedeps .usedeps
.iter() .iter()
.map(|u| u.to_string()) .map(UseDep::to_string)
.intersperse(",".to_string()) .intersperse(",".to_string())
.collect::<String>(); .collect::<String>();

View File

@@ -77,7 +77,7 @@ impl<'a> Parseable<'a, &'a str> for VersionNumbers {
.map(|output: &str| VersionNumber(output.to_string())) .map(|output: &str| VersionNumber(output.to_string()))
.separated_by(tag(".")) .separated_by(tag("."))
.at_least(1) .at_least(1)
.map(|numbers| VersionNumbers(numbers)) .map(VersionNumbers)
} }
} }
@@ -88,7 +88,7 @@ impl<'a> Parseable<'a, &'a str> for VersionSuffixes {
VersionSuffix::parser() VersionSuffix::parser()
.separated_by(tag("_")) .separated_by(tag("_"))
.at_least(1) .at_least(1)
.map(|suffixes| VersionSuffixes(suffixes)) .map(VersionSuffixes)
} }
} }
@@ -180,8 +180,8 @@ impl<'a> Parseable<'a, &'a str> for Slot {
.opt() .opt()
.and(SlotName::parser().preceded_by(tag("/")).opt()) .and(SlotName::parser().preceded_by(tag("/")).opt())
.and(SlotOperator::parser().opt()) .and(SlotOperator::parser().opt())
.map(|((slot, sub), operator)| Slot { .map(|((primary, sub), operator)| Slot {
slot, primary,
sub, sub,
operator, operator,
}) })
@@ -201,6 +201,7 @@ impl<'a> Parseable<'a, &'a str> for UseDepSign {
impl<'a> Parseable<'a, &'a str> for UseDep { impl<'a> Parseable<'a, &'a str> for UseDep {
type Parser = impl Parser<&'a str, Output = Self>; type Parser = impl Parser<&'a str, Output = Self>;
#[allow(clippy::many_single_char_names)]
fn parser() -> Self::Parser { fn parser() -> Self::Parser {
let a = UseFlag::parser() let a = UseFlag::parser()
.and(UseDepSign::parser().opt()) .and(UseDepSign::parser().opt())
@@ -321,7 +322,7 @@ impl<'a> Parseable<'a, &'a str> for Atom {
.numbers() .numbers()
.get() .get()
.iter() .iter()
.any(|number| number.get().contains("*")) => .any(|number| number.get().contains('*')) =>
{ {
true true
} }
@@ -414,7 +415,7 @@ mod test {
fn test_invalid_usedep() { fn test_invalid_usedep() {
let it = InputIter::new("foo-bar:slot/sub=[!use]"); let it = InputIter::new("foo-bar:slot/sub=[!use]");
assert!(Atom::parser().check_finished(it).is_err()) assert!(Atom::parser().check_finished(it).is_err());
} }
#[test] #[test]

View File

@@ -154,10 +154,10 @@ impl<'a> Parseable<'a, &'a str> for Conditional {
UseFlag::parser() UseFlag::parser()
.preceded_by(tag("!")) .preceded_by(tag("!"))
.followed_by(tag("?")) .followed_by(tag("?"))
.map(|flag| Conditional::Negative(flag)) .map(Conditional::Negative)
.or(UseFlag::parser() .or(UseFlag::parser()
.followed_by(tag("?")) .followed_by(tag("?"))
.map(|flag| Conditional::Positive(flag))) .map(Conditional::Positive))
} }
} }
@@ -180,7 +180,7 @@ mod test {
for test in tests { for test in tests {
SrcUri::parser() SrcUri::parser()
.check_finished(InputIter::new(test)) .check_finished(InputIter::new(test))
.unwrap() .unwrap();
} }
} }

View File

@@ -199,7 +199,7 @@ fn read_slot(input: &str) -> Option<Result<atom::Slot, Error>> {
fn read_homepage(input: &str) -> Option<String> { fn read_homepage(input: &str) -> Option<String> {
input input
.lines() .lines()
.find_map(|line| line.strip_prefix("HOMEPAGE=").map(|s| s.to_string())) .find_map(|line| line.strip_prefix("HOMEPAGE=").map(str::to_string))
} }
fn read_src_uri(input: &str) -> Option<Result<Vec<Depend<SrcUri>>, Error>> { fn read_src_uri(input: &str) -> Option<Result<Vec<Depend<SrcUri>>, Error>> {
@@ -272,7 +272,7 @@ fn read_license(input: &str) -> Option<Result<Vec<Depend<License>>, Error>> {
fn read_description(input: &str) -> Option<String> { fn read_description(input: &str) -> Option<String> {
input input
.lines() .lines()
.find_map(|line| line.strip_prefix("DESCRIPTION=").map(|s| s.to_string())) .find_map(|line| line.strip_prefix("DESCRIPTION=").map(str::to_string))
} }
fn read_depend(input: &str) -> Option<Result<Vec<Depend<Atom>>, Error>> { fn read_depend(input: &str) -> Option<Result<Vec<Depend<Atom>>, Error>> {

View File

@@ -1,5 +1,5 @@
#![deny(clippy::pedantic, unused_imports)] #![deny(clippy::pedantic, unused_imports)]
#![allow(dead_code, unstable_name_collisions)] #![allow(dead_code, unstable_name_collisions, clippy::missing_errors_doc)]
#![feature(impl_trait_in_assoc_type)] #![feature(impl_trait_in_assoc_type)]
use mon::{Parser, input::Input}; use mon::{Parser, input::Input};