Skip to content

Commit

Permalink
Fix new clippy warnings/errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
afranchuk committed Oct 16, 2023
1 parent 1ef4d9a commit 3a19ffd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ impl core::ops::Deref for VersionReq {
}
impl cmp::PartialOrd for VersionReq {
fn partial_cmp(&self, other: &VersionReq) -> Option<cmp::Ordering> {
format!("{self}").partial_cmp(&format!("{other}"))
Some(self.cmp(other))
}
}
impl cmp::Ord for VersionReq {
fn cmp(&self, other: &VersionReq) -> cmp::Ordering {
format!("{self}").cmp(&format!("{other}"))
}
}
impl VersionReq {
Expand Down Expand Up @@ -309,18 +314,18 @@ impl AuditEntry {
/// different than the order we want for serialization.
impl cmp::PartialOrd for AuditEntry {
fn partial_cmp<'a>(&'a self, other: &'a AuditEntry) -> Option<cmp::Ordering> {
let tuple = |x: &'a AuditEntry| (&x.kind, &x.criteria, &x.who, &x.notes);
tuple(self).partial_cmp(&tuple(other))
Some(self.cmp(other))
}
}

impl cmp::Ord for AuditEntry {
fn cmp(&self, other: &AuditEntry) -> cmp::Ordering {
self.partial_cmp(other).unwrap()
fn cmp<'a>(&'a self, other: &'a AuditEntry) -> cmp::Ordering {
let tuple = |x: &'a AuditEntry| (&x.kind, &x.criteria, &x.who, &x.notes);
tuple(self).cmp(&tuple(other))
}
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum AuditKind {
Full { version: VetVersion },
Delta { from: VetVersion, to: VetVersion },
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,8 @@ async fn fix_audit_as(
cfg.metadata
.packages
.iter()
.filter_map(|p| (p.name == error.package).then(|| p.vet_version()))
.filter(|&p| (p.name == error.package))
.map(|p| p.vet_version())
.collect()
};
// This can only fail if there's a logical error in `check_audit_as_crates_io`.
Expand Down
7 changes: 5 additions & 2 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,10 +1168,13 @@ impl Out for BasicTestOutput {

/// Format a diff between the old and new strings for reporting.
fn generate_diff(old: &str, new: &str) -> String {
use fmt::Write;
similar::utils::diff_lines(similar::Algorithm::Myers, old, new)
.into_iter()
.map(|(tag, line)| format!("{tag}{line}"))
.collect()
.fold(String::new(), |mut s, (tag, line)| {
write!(&mut s, "{tag}{line}").unwrap();
s
})
}

/// Generate a diff between two values returned from `Store::mock_commit`.
Expand Down

0 comments on commit 3a19ffd

Please sign in to comment.