From f0568c164aa9a12928b66e1ea40790c1f4ff1bb1 Mon Sep 17 00:00:00 2001 From: Nick Santana Date: Tue, 17 Oct 2023 14:33:37 -0700 Subject: [PATCH] Remove uneeded use of `into_iter()` Some other minor clippy changes - use slices for temporary locals instead of vec![]. - use `let _` instead of drop() on copy types. - Be explicit when creating a slice of type Range --- consensus/scp/src/slot.rs | 5 ++--- .../src/byzantine_ledger/pending_values.rs | 4 ++-- consensus/service/src/byzantine_ledger/worker.rs | 2 +- fog/distribution/src/main.rs | 4 ++-- fog/ledger/server/tests/router_connection.rs | 4 ++-- fog/ledger/test_infra/src/lib.rs | 2 +- fog/sample-paykit/src/cached_tx_data/mod.rs | 2 +- fog/test_infra/src/mock_users.rs | 6 ++---- .../sync/src/ledger_sync/ledger_sync_service.rs | 9 +++------ mobilecoind/src/payments.rs | 15 +++++---------- sgx/sync/src/mutex.rs | 6 +++--- transaction/builder/src/input_credentials.rs | 6 ++---- 12 files changed, 26 insertions(+), 39 deletions(-) diff --git a/consensus/scp/src/slot.rs b/consensus/scp/src/slot.rs index a8def15cc6..c731c7ddd8 100644 --- a/consensus/scp/src/slot.rs +++ b/consensus/scp/src/slot.rs @@ -322,7 +322,7 @@ impl ScpSlot for Slot return Ok(None); } - self.W.extend(valid_values.into_iter()); + self.W.extend(valid_values); self.do_nominate_phase(); self.do_ballot_protocol(); Ok(self.out_msg()) @@ -633,8 +633,7 @@ impl Slot { // Invariant: X and Y are disjoint. assert!(self.X.is_disjoint(&self.Y)); - self.Z - .extend(self.additional_values_confirmed_nominated().into_iter()); + self.Z.extend(self.additional_values_confirmed_nominated()); // let mut new_Z = self.additional_values_confirmed_nominated(); // if !new_Z.is_empty() { // new_Z.append(&mut self.Z); diff --git a/consensus/service/src/byzantine_ledger/pending_values.rs b/consensus/service/src/byzantine_ledger/pending_values.rs index 71c79d2b76..a518ad0039 100644 --- a/consensus/service/src/byzantine_ledger/pending_values.rs +++ b/consensus/service/src/byzantine_ledger/pending_values.rs @@ -175,7 +175,7 @@ mod tests { let mint_tx_manager = MockMintTxManager::new(); // A few test values. - let values = vec![TxHash([1u8; 32]), TxHash([2u8; 32]), TxHash([3u8; 32])]; + let values = [TxHash([1u8; 32]), TxHash([2u8; 32]), TxHash([3u8; 32])]; // `validate` should be called one for each pending value. tx_manager @@ -254,7 +254,7 @@ mod tests { let mint_tx_manager = MockMintTxManager::new(); // A few test values. - let tx_hashes = vec![TxHash([1u8; 32]), TxHash([2u8; 32]), TxHash([3u8; 32])]; + let tx_hashes = [TxHash([1u8; 32]), TxHash([2u8; 32]), TxHash([3u8; 32])]; let values: Vec = tx_hashes .iter() diff --git a/consensus/service/src/byzantine_ledger/worker.rs b/consensus/service/src/byzantine_ledger/worker.rs index e5896d818e..e525ffee2a 100644 --- a/consensus/service/src/byzantine_ledger/worker.rs +++ b/consensus/service/src/byzantine_ledger/worker.rs @@ -739,7 +739,7 @@ impl< let entry = self .unavailable_tx_hashes .entry(from_responder_id.clone()) - .or_insert_with(BTreeSet::default); + .or_default(); entry.extend(tx_hashes); return false; } diff --git a/fog/distribution/src/main.rs b/fog/distribution/src/main.rs index af95eaf50b..7effffacd6 100755 --- a/fog/distribution/src/main.rs +++ b/fog/distribution/src/main.rs @@ -836,7 +836,7 @@ fn get_membership_proofs( .collect(); let proofs = ledger_db.get_tx_out_proof_of_memberships(&indexes).unwrap(); - utxos.iter().cloned().zip(proofs.into_iter()).collect() + utxos.iter().cloned().zip(proofs).collect() } /// Get ring mixins for a transaction from the ledger @@ -864,7 +864,7 @@ fn get_rings( .unwrap(); // Create an iterator that returns (index, proof) elements. - let mut indexes_and_proofs_iterator = sampled_indices_vec.into_iter().zip(proofs.into_iter()); + let mut indexes_and_proofs_iterator = sampled_indices_vec.into_iter().zip(proofs); // Convert that into a Vec> let mut rings_with_proofs = Vec::new(); diff --git a/fog/ledger/server/tests/router_connection.rs b/fog/ledger/server/tests/router_connection.rs index 68c1ce44f0..a7a0b3b573 100644 --- a/fog/ledger/server/tests/router_connection.rs +++ b/fog/ledger/server/tests/router_connection.rs @@ -612,7 +612,7 @@ fn fog_ledger_blocks_api_test(logger: Logger) { ); // Try to get a block - let queries = [0..1]; + let queries = [0..1; 1]; let result = client.get_blocks(&queries).unwrap(); // Check that we got 1 block, as expected assert_eq!(result.blocks.len(), 1); @@ -627,7 +627,7 @@ fn fog_ledger_blocks_api_test(logger: Logger) { assert_eq!(result.global_txo_count, ledger.num_txos().unwrap()); // Try to get two blocks - let queries = [1..3]; + let queries = [1..3; 1]; let result = client.get_blocks(&queries).unwrap(); // Check that we got 2 blocks, as expected diff --git a/fog/ledger/test_infra/src/lib.rs b/fog/ledger/test_infra/src/lib.rs index 387909726a..49be297bda 100644 --- a/fog/ledger/test_infra/src/lib.rs +++ b/fog/ledger/test_infra/src/lib.rs @@ -366,7 +366,7 @@ impl ShardProxyServer { let server = Server::bind(address).serve(make_service); let graceful = server.with_graceful_shutdown(Self::shutdown(rx)); - let server_handle = tokio::spawn(async move { graceful.await }); + let server_handle = tokio::spawn(graceful); Self { server_handle: Some(server_handle), diff --git a/fog/sample-paykit/src/cached_tx_data/mod.rs b/fog/sample-paykit/src/cached_tx_data/mod.rs index 8ae8d91003..42eef6527d 100644 --- a/fog/sample-paykit/src/cached_tx_data/mod.rs +++ b/fog/sample-paykit/src/cached_tx_data/mod.rs @@ -1474,7 +1474,7 @@ mod tests { #[test] fn calculate_updated_missed_block_ranges_multiple_indices_returns_block_range_with_indices() { - let indices = vec![(5, 11), (34, 40), (1, 3)]; + let indices = [(5, 11), (34, 40), (1, 3)]; let mut missed_block_ranges = Vec::new(); for (start_block, end_block) in indices.iter() { diff --git a/fog/test_infra/src/mock_users.rs b/fog/test_infra/src/mock_users.rs index a9752e9030..952594ce49 100644 --- a/fog/test_infra/src/mock_users.rs +++ b/fog/test_infra/src/mock_users.rs @@ -73,9 +73,7 @@ pub fn test_block_to_inputs_and_expected_outputs( let mut result_delta: Delta = Default::default(); for (ref upriv, ref txo) in pairs.iter() { - let user_result_set = result_delta - .entry(upriv.clone()) - .or_insert_with(HashSet::default); + let user_result_set = result_delta.entry(upriv.clone()).or_default(); let fog_tx_out = FogTxOut::try_from(txo).unwrap(); let meta = FogTxOutMetadata { @@ -204,7 +202,7 @@ impl UserPool { let user_id = &self.users[user_idx].0; result .entry(user_id.clone()) - .or_insert_with(Vec::new) + .or_default() .push(make_random_tx(rng, acct_server_pubkey, &user_id.get_hint())); } result diff --git a/ledger/sync/src/ledger_sync/ledger_sync_service.rs b/ledger/sync/src/ledger_sync/ledger_sync_service.rs index 1c5882bfc6..6f2b12f9fe 100644 --- a/ledger/sync/src/ledger_sync/ledger_sync_service.rs +++ b/ledger/sync/src/ledger_sync/ledger_sync_service.rs @@ -546,13 +546,10 @@ fn group_by_block( for (responder_id, blocks) in node_to_blocks { for block in blocks.iter() { let block_id_to_group: &mut HashMap> = - block_index_to_grouping - .entry(block.index) - .or_insert_with(HashMap::default); + block_index_to_grouping.entry(block.index).or_default(); - let group: &mut HashSet = block_id_to_group - .entry(block.id.clone()) - .or_insert_with(HashSet::default); + let group: &mut HashSet = + block_id_to_group.entry(block.id.clone()).or_default(); group.insert(responder_id.clone()); } diff --git a/mobilecoind/src/payments.rs b/mobilecoind/src/payments.rs index c819e9d80a..be9f66756b 100644 --- a/mobilecoind/src/payments.rs +++ b/mobilecoind/src/payments.rs @@ -425,10 +425,7 @@ impl = { let tx_outs: Vec = inputs.iter().map(|utxo| utxo.tx_out.clone()).collect(); let proofs = self.get_membership_proofs(&tx_outs)?; - inputs.iter().cloned().zip(proofs.into_iter()).collect() + inputs.iter().cloned().zip(proofs).collect() }; log::trace!(logger, "Got membership proofs"); @@ -1060,10 +1057,8 @@ impl = mixins - .into_iter() - .zip(membership_proofs.into_iter()) - .collect(); + let mixins_with_proofs: Vec<(TxOut, TxOutMembershipProof)> = + mixins.into_iter().zip(membership_proofs).collect(); // Group mixins and proofs into individual rings. let result: Vec> = mixins_with_proofs diff --git a/sgx/sync/src/mutex.rs b/sgx/sync/src/mutex.rs index 5b23122ff7..78923d5031 100644 --- a/sgx/sync/src/mutex.rs +++ b/sgx/sync/src/mutex.rs @@ -356,7 +356,7 @@ impl SgxMutex { /// the current thread. pub fn lock(&self) -> LockResult> { unsafe { - drop(self.inner.lock()); + let _ = self.inner.lock(); SgxMutexGuard::new(self) } } @@ -416,7 +416,7 @@ impl SgxMutex { (ptr::read(inner), ptr::read(poison), ptr::read(data)) }; mem::forget(self); - drop(inner.destroy()); + let _ = inner.destroy(); drop(inner); poison::map_result(poison.borrow(), |_| data.into_inner()) @@ -442,7 +442,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for SgxMutex { fn drop(&mut self) { // IMPORTANT: This code must be kept in sync with `Mutex::into_inner`. unsafe { - drop(self.inner.destroy()); + let _ = self.inner.destroy(); } } } diff --git a/transaction/builder/src/input_credentials.rs b/transaction/builder/src/input_credentials.rs index 37b2a718d7..fb004d5aba 100644 --- a/transaction/builder/src/input_credentials.rs +++ b/transaction/builder/src/input_credentials.rs @@ -66,10 +66,8 @@ impl InputCredentials { // Sort the ring and the corresponding proofs. This ensures that the ordering // of mixins in the transaction does not depend on the user's implementation for // obtaining mixins. - let mut ring_and_proofs: Vec<(TxOut, TxOutMembershipProof)> = ring - .into_iter() - .zip(membership_proofs.into_iter()) - .collect(); + let mut ring_and_proofs: Vec<(TxOut, TxOutMembershipProof)> = + ring.into_iter().zip(membership_proofs).collect(); ring_and_proofs .sort_by(|(tx_out_a, _), (tx_out_b, _)| tx_out_a.public_key.cmp(&tx_out_b.public_key));