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

View File

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

View File

@@ -154,10 +154,10 @@ impl<'a> Parseable<'a, &'a str> for Conditional {
UseFlag::parser()
.preceded_by(tag("!"))
.followed_by(tag("?"))
.map(|flag| Conditional::Negative(flag))
.map(Conditional::Negative)
.or(UseFlag::parser()
.followed_by(tag("?"))
.map(|flag| Conditional::Positive(flag)))
.map(Conditional::Positive))
}
}
@@ -180,7 +180,7 @@ mod test {
for test in tests {
SrcUri::parser()
.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> {
input
.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>> {
@@ -272,7 +272,7 @@ fn read_license(input: &str) -> Option<Result<Vec<Depend<License>>, Error>> {
fn read_description(input: &str) -> Option<String> {
input
.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>> {

View File

@@ -1,5 +1,5 @@
#![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)]
use mon::{Parser, input::Input};