From df2471fb95dbc50a1e5eaf6e363c016fb97418e4 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 28 Sep 2021 19:03:57 +0300 Subject: 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 --- openpgp/src/cert.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'openpgp') 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 } -- cgit v1.2.3