summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-09-28 19:03:57 +0300
committerLars Wirzenius <liw@sequoia-pgp.org>2021-09-30 08:31:14 +0300
commitdf2471fb95dbc50a1e5eaf6e363c016fb97418e4 (patch)
treed93b8159ab82ca6c2fbd687de0f41e114dbfa671 /openpgp
parentf7d55f1f915065d6b886e21c4efb7452cfa10e1c (diff)
Remove evaluation order dependence
In this code: self.user_attributes.retain(|_| (keep[i], i += 1).0); it can be unclear to the reader that the increment of i actually happens before keep is indexed. Especially so for people who've been inflicted by C and its many surprising reasons for undefined behavior. It seems better to write this using an iterator. Found by clippy lint eval_order_dependence: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/cert.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/openpgp/src/cert.rs b/openpgp/src/cert.rs
index 1da3390e..a8a9f65a 100644
--- a/openpgp/src/cert.rs
+++ b/openpgp/src/cert.rs
@@ -2690,8 +2690,8 @@ impl Cert {
}
// Note: Vec::retain visits the elements in the original
// order.
- let mut i = 0;
- self.userids.retain(|_| (keep[i], i += 1).0);
+ let mut keep = keep.iter();
+ self.userids.retain(|_| *keep.next().unwrap());
self
}
@@ -2729,8 +2729,8 @@ impl Cert {
}
// Note: Vec::retain visits the elements in the original
// order.
- let mut i = 0;
- self.user_attributes.retain(|_| (keep[i], i += 1).0);
+ let mut keep = keep.iter();
+ self.user_attributes.retain(|_| *keep.next().unwrap());
self
}
@@ -2783,8 +2783,8 @@ impl Cert {
}
// Note: Vec::retain visits the elements in the original
// order.
- let mut i = 0;
- self.subkeys.retain(|_| (keep[i], i += 1).0);
+ let mut keep = keep.iter();
+ self.subkeys.retain(|_| *keep.next().unwrap());
self
}