summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2021-11-22 20:41:01 +0100
committerNora Widdecke <nora@sequoia-pgp.org>2021-11-29 11:53:56 +0100
commit58946b2da1bf12c42854c03e67d6ba0a540ce317 (patch)
tree2c8bc477410b0721af912c340f9f21eca204592d /openpgp
parent307a6d739df7728b9676b51743edc42ef45f7379 (diff)
Use std::mem::take instead of std::mem::replace, for clarity.
- Replace let bar = std::mem::replace(&foo, Default::Default()); with let bar = std::mem::take(&foo); The new version seems a little clearer. - Found by clippy: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/cert.rs20
-rw-r--r--openpgp/src/parse/hashed_reader.rs3
-rw-r--r--openpgp/src/policy/cutofflist.rs4
3 files changed, 11 insertions, 16 deletions
diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs
index d9f7decd..2e0e33ee 100644
--- a/openpgp/src/cert.rs
+++ b/openpgp/src/cert.rs
@@ -1527,9 +1527,7 @@ impl Cert {
t!("check!({}, {}, {:?}, {}, ...)",
$desc, stringify!($binding), $binding.$sigs,
stringify!($verify_method));
- for mut sig in mem::replace(&mut $binding.$sigs, Vec::new())
- .into_iter()
- {
+ for mut sig in mem::take(&mut $binding.$sigs).into_iter() {
match sig.$verify_method(self.primary.key(),
self.primary.key(),
$($verify_args),*) {
@@ -1567,9 +1565,7 @@ impl Cert {
t!("check_3rd_party!({}, {}, {:?}, {}, {}, ...)",
$desc, stringify!($binding), $binding.$sigs,
stringify!($verify_method), stringify!($hash_method));
- for mut sig in mem::replace(&mut $binding.$sigs, Vec::new())
- .into_iter()
- {
+ for mut sig in mem::take(&mut $binding.$sigs) {
// Use hash prefix as heuristic.
let key = self.primary.key();
match sig.hash_algo().context().and_then(|mut ctx| {
@@ -1709,7 +1705,7 @@ impl Cert {
// See if the signatures that didn't validate are just out of
// place.
let mut bad_sigs: Vec<(Option<usize>, Signature)> =
- mem::replace(&mut self.bad, Vec::new()).into_iter()
+ std::mem::take(&mut self.bad).into_iter()
.map(|sig| {
t!("We're going to reconsider bad signature {:?}", sig);
(None, sig)
@@ -1720,15 +1716,15 @@ impl Cert {
// remember where we took them from.
for (i, c) in self.unknowns.iter_mut().enumerate() {
for sig in
- mem::replace(&mut c.self_signatures, Vec::new()).into_iter()
+ std::mem::take(&mut c.self_signatures).into_iter()
.chain(
- mem::replace(&mut c.certifications, Vec::new()).into_iter())
+ std::mem::take(&mut c.certifications).into_iter())
.chain(
- mem::replace(&mut c.attestations, Vec::new()).into_iter())
+ std::mem::take(&mut c.attestations).into_iter())
.chain(
- mem::replace(&mut c.self_revocations, Vec::new()).into_iter())
+ std::mem::take(&mut c.self_revocations).into_iter())
.chain(
- mem::replace(&mut c.other_revocations, Vec::new()).into_iter())
+ std::mem::take(&mut c.other_revocations).into_iter())
{
t!("We're going to reconsider {:?} on unknown component #{}",
sig, i);
diff --git a/openpgp/src/parse/hashed_reader.rs b/openpgp/src/parse/hashed_reader.rs
index 0568829d..00f56427 100644
--- a/openpgp/src/parse/hashed_reader.rs
+++ b/openpgp/src/parse/hashed_reader.rs
@@ -427,8 +427,7 @@ mod test {
let cookie = reader.cookie_mut();
- let mut hashes = mem::replace(&mut cookie.sig_group_mut().hashes,
- Default::default());
+ let mut hashes = std::mem::take(&mut cookie.sig_group_mut().hashes);
for mode in hashes.iter_mut() {
let hash = mode.as_mut();
let algo = hash.algo();
diff --git a/openpgp/src/policy/cutofflist.rs b/openpgp/src/policy/cutofflist.rs
index 98d4af78..d21d83a5 100644
--- a/openpgp/src/policy/cutofflist.rs
+++ b/openpgp/src/policy/cutofflist.rs
@@ -1,5 +1,5 @@
use std::fmt;
-use std::mem;
+
use std::ops::{Index, IndexMut};
use crate::{
@@ -51,7 +51,7 @@ impl<'a, T> VecOrSlice<'a, T> {
where T: Clone
{
let mut v : Vec<T> = match self {
- VecOrSlice::Vec(ref mut v) => mem::replace(v, Vec::new()),
+ VecOrSlice::Vec(ref mut v) => std::mem::take(v),
VecOrSlice::Slice(s) => s.to_vec(),
VecOrSlice::Empty() => Vec::with_capacity(size),
};