summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--ffi/tests/c-tests.rs5
-rw-r--r--openpgp-ffi/tests/c-tests.rs5
-rw-r--r--openpgp/src/cert.rs20
-rw-r--r--openpgp/src/parse/hashed_reader.rs3
-rw-r--r--openpgp/src/policy/cutofflist.rs4
-rw-r--r--sq/src/commands/inspect.rs2
6 files changed, 16 insertions, 23 deletions
diff --git a/ffi/tests/c-tests.rs b/ffi/tests/c-tests.rs
index da05ad1a..fface8f0 100644
--- a/ffi/tests/c-tests.rs
+++ b/ffi/tests/c-tests.rs
@@ -8,7 +8,6 @@ use std::io::{self, BufRead, Write};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;
-use std::mem::replace;
/// Hooks into Rust's test system to extract, compile and run c tests.
#[test]
@@ -163,7 +162,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
if let Some(name) = exported_function_name(&line) {
if !test.is_empty() {
- fun(path, test_starts_at, name, replace(&mut test, vec![]),
+ fun(path, test_starts_at, name, std::mem::take(&mut test),
run)?;
test.clear();
}
@@ -179,7 +178,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
path.file_stem().unwrap().to_string_lossy(),
lineno); // XXX: nicer to point to the top
- fun(path, test_starts_at, &name, replace(&mut test, Vec::new()),
+ fun(path, test_starts_at, &name, std::mem::take(&mut test),
run)?;
test.clear();
in_test = false;
diff --git a/openpgp-ffi/tests/c-tests.rs b/openpgp-ffi/tests/c-tests.rs
index a93653db..ecd68bcf 100644
--- a/openpgp-ffi/tests/c-tests.rs
+++ b/openpgp-ffi/tests/c-tests.rs
@@ -8,7 +8,6 @@ use std::io::{self, BufRead, Write};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str::FromStr;
-use std::mem::replace;
/// Hooks into Rust's test system to extract, compile and run c tests.
#[test]
@@ -162,7 +161,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
if let Some(name) = exported_function_name(&line) {
if !test.is_empty() {
- fun(path, test_starts_at, name, replace(&mut test, vec![]),
+ fun(path, test_starts_at, name, std::mem::take(&mut test),
run)?;
test.clear();
}
@@ -178,7 +177,7 @@ fn for_all_tests<F>(path: &Path, mut fun: F)
path.file_stem().unwrap().to_string_lossy(),
lineno); // XXX: nicer to point to the top
- fun(path, test_starts_at, &name, replace(&mut test, Vec::new()),
+ fun(path, test_starts_at, &name, std::mem::take(&mut test),
run)?;
test.clear();
in_test = false;
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),
};
diff --git a/sq/src/commands/inspect.rs b/sq/src/commands/inspect.rs
index 7d136ab0..2d2037a9 100644
--- a/sq/src/commands/inspect.rs
+++ b/sq/src/commands/inspect.rs
@@ -46,7 +46,7 @@ pub fn inspect(m: &clap::ArgMatches, policy: &dyn Policy, output: &mut dyn io::W
type_called = true;
}
let pp = openpgp::PacketPile::from(
- ::std::mem::replace(&mut packets, Vec::new()));
+ std::mem::take(&mut packets));
let cert = openpgp::Cert::try_from(pp)?;
inspect_cert(policy, output, &cert,
print_certifications)?;