From 8b06d88ede1315af63250b00dbefe8ec2804eda8 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 27 Sep 2021 16:30:38 +0300 Subject: 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 --- ipc/src/keybox.rs | 6 +++--- net/src/updates.rs | 8 ++++---- openpgp-ffi/src/parse/stream.rs | 1 + 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 { (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 { - 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 { - 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> { 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 { -- cgit v1.2.3