summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-09-27 16:30:38 +0300
committerLars Wirzenius <liw@sequoia-pgp.org>2021-09-30 08:31:11 +0300
commit8b06d88ede1315af63250b00dbefe8ec2804eda8 (patch)
tree45a77c6ef7eae2f02cb795713fb7445e12a4c7b0
parentfe78f2fc0baa68aa2b9c0125c1b89dc23121d68b (diff)
Avoid redundant closures
If a closure just passes the argument it gets to a function, the closure is usually redundant and you can just use the function instead of the closure. Thus, instead of this: iter().map(|x| foo(x)) you can write this: iter().map(foo) This is shorter and simpler. Sometimes it doesn't work and the closure is necessary. Such locations can be marked with `#[allow(clippy::redundant_closure)]`. Found by clippy lint redundant_closure: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
-rw-r--r--ipc/src/keybox.rs6
-rw-r--r--net/src/updates.rs8
-rw-r--r--openpgp-ffi/src/parse/stream.rs1
3 files changed, 8 insertions, 7 deletions
diff --git a/ipc/src/keybox.rs b/ipc/src/keybox.rs
index 7ed481b7..c098631d 100644
--- a/ipc/src/keybox.rs
+++ b/ipc/src/keybox.rs
@@ -162,13 +162,13 @@ impl KeyboxRecord {
let record = KeyboxRecord::Unknown(bytes.clone());
match record.typ() {
KeyboxRecordType::Header => {
- HeaderRecord::new(bytes).map(|r| KeyboxRecord::Header(r))
+ HeaderRecord::new(bytes).map(KeyboxRecord::Header)
}
KeyboxRecordType::OpenPGP => {
- OpenPGPRecordV1::new(&record).map(|r| KeyboxRecord::OpenPGP(r))
+ OpenPGPRecordV1::new(&record).map(KeyboxRecord::OpenPGP)
}
KeyboxRecordType::X509 => {
- X509Record::new(bytes).map(|r| KeyboxRecord::X509(r))
+ X509Record::new(bytes).map(KeyboxRecord::X509)
}
KeyboxRecordType::Unknown(_) => Ok(record),
}
diff --git a/net/src/updates.rs b/net/src/updates.rs
index f4ff91dc..8313cd62 100644
--- a/net/src/updates.rs
+++ b/net/src/updates.rs
@@ -79,7 +79,7 @@ impl Manifest {
/// Iterates over all epochs contained in this Update Manifest.
pub fn epochs(&self) -> impl Iterator<Item = Epoch> {
(self.start.0..self.end.0 + 1).into_iter()
- .map(|n| Epoch(n))
+ .map(Epoch)
}
/// Returns the start epoch.
@@ -218,12 +218,12 @@ impl Epoch {
/// Returns the previous Epoch, if any.
pub fn pred(&self) -> Option<Epoch> {
- self.0.checked_sub(1).map(|e| Epoch(e))
+ self.0.checked_sub(1).map(Epoch)
}
/// Returns the next Epoch, if any.
pub fn succ(&self) -> Option<Epoch> {
- self.0.checked_add(1).map(|e| Epoch(e))
+ self.0.checked_add(1).map(Epoch)
}
/// Returns an iterator over all epochs starting from this one to
@@ -231,7 +231,7 @@ impl Epoch {
pub fn since(&self, other: Epoch)
-> anyhow::Result<impl Iterator<Item = Epoch>> {
if other <= *self {
- Ok((other.0 + 1..self.0).into_iter().rev().map(|e| Epoch(e)))
+ Ok((other.0 + 1..self.0).into_iter().rev().map(Epoch))
} else {
Err(anyhow::anyhow!("other is later than self"))
}
diff --git a/openpgp-ffi/src/parse/stream.rs b/openpgp-ffi/src/parse/stream.rs
index 62ba4b1e..afd32fee 100644
--- a/openpgp-ffi/src/parse/stream.rs
+++ b/openpgp-ffi/src/parse/stream.rs
@@ -494,6 +494,7 @@ impl VerificationHelper for VHelper {
&mut free);
// Free the KeyID wrappers.
+ #[allow(clippy::redundant_closure)]
ids.into_iter().for_each(|id| super::super::keyid::pgp_keyid_free(id));
if result != Status::Success {