From bd873e7162261a8369a08312d2643a86f798b745 Mon Sep 17 00:00:00 2001 From: Divma Date: Fri, 23 Sep 2022 03:52:46 +0000 Subject: [PATCH] New rust lints for rustc 1.64.0 (#3602) ## Issue Addressed fixes lints from the last rust release ## Proposed Changes Fix the lints, most of the lints by `clippy::question-mark` are false positives in the form of https://github.com/rust-lang/rust-clippy/issues/9518 so it's allowed for now ## Additional Info --- Makefile | 3 ++- beacon_node/beacon_chain/src/beacon_chain.rs | 6 +++--- .../beacon_chain/src/schema_change/migration_schema_v7.rs | 6 +++--- beacon_node/beacon_chain/src/sync_committee_verification.rs | 2 +- beacon_node/beacon_chain/src/test_utils.rs | 2 +- beacon_node/http_api/src/lib.rs | 2 +- consensus/merkle_proof/src/lib.rs | 4 +--- consensus/ssz_types/src/fixed_vector.rs | 2 +- consensus/ssz_types/src/variable_list.rs | 2 +- validator_client/src/preparation_service.rs | 2 +- 10 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 6b5c6b3e5..6119f0dc0 100644 --- a/Makefile +++ b/Makefile @@ -153,7 +153,8 @@ lint: -A clippy::derive_partial_eq_without_eq \ -A clippy::from-over-into \ -A clippy::upper-case-acronyms \ - -A clippy::vec-init-then-push + -A clippy::vec-init-then-push \ + -A clippy::question-mark nightly-lint: cp .github/custom/clippy.toml . diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index b0fac779a..2a449f64b 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -809,7 +809,7 @@ impl BeaconChain { if let Some(request_root) = request_root_opt { if let Ok(prev_root) = state.get_block_root(prev_slot) { - return Ok(Some((*prev_root != request_root).then(|| request_root))); + return Ok(Some((*prev_root != request_root).then_some(request_root))); } } @@ -831,7 +831,7 @@ impl BeaconChain { slot: curr_slot, }); } - Ok((curr_root != prev_root).then(|| curr_root)) + Ok((curr_root != prev_root).then_some(curr_root)) } else { Ok(None) } @@ -2871,7 +2871,7 @@ impl BeaconChain { .pubkeys .iter() .zip(sync_aggregate.sync_committee_bits.iter()) - .filter_map(|(pubkey, bit)| bit.then(|| pubkey)) + .filter_map(|(pubkey, bit)| bit.then_some(pubkey)) .collect::>(); validator_monitor.register_sync_aggregate_in_block( diff --git a/beacon_node/beacon_chain/src/schema_change/migration_schema_v7.rs b/beacon_node/beacon_chain/src/schema_change/migration_schema_v7.rs index 4a9a78db7..d953d3002 100644 --- a/beacon_node/beacon_chain/src/schema_change/migration_schema_v7.rs +++ b/beacon_node/beacon_chain/src/schema_change/migration_schema_v7.rs @@ -212,7 +212,7 @@ fn map_relevant_epochs_to_roots( let root = iter .find_map(|next| match next { - Ok((root, slot)) => (slot == start_slot).then(|| Ok(root)), + Ok((root, slot)) => (slot == start_slot).then_some(Ok(root)), Err(e) => Some(Err(format!("{:?}", e))), }) .transpose()? @@ -286,7 +286,7 @@ fn find_finalized_descendant_heads( .filter_map(|(index, node)| { (!nodes_referenced_as_parents.contains(&index) && fork_choice.is_descendant(finalized_root, node.root)) - .then(|| HeadInfo { + .then_some(HeadInfo { index, root: node.root, slot: node.slot, @@ -306,7 +306,7 @@ fn update_store_justified_checkpoint( .filter_map(|node| { (node.finalized_checkpoint == Some(persisted_fork_choice.fork_choice_store.finalized_checkpoint)) - .then(|| node.justified_checkpoint) + .then_some(node.justified_checkpoint) .flatten() }) .max_by_key(|justified_checkpoint| justified_checkpoint.epoch) diff --git a/beacon_node/beacon_chain/src/sync_committee_verification.rs b/beacon_node/beacon_chain/src/sync_committee_verification.rs index 7d56af793..4b4228e71 100644 --- a/beacon_node/beacon_chain/src/sync_committee_verification.rs +++ b/beacon_node/beacon_chain/src/sync_committee_verification.rs @@ -343,7 +343,7 @@ impl VerifiedSyncContribution { let participant_pubkeys = sync_subcommittee_pubkeys .into_iter() .zip(contribution.aggregation_bits.iter()) - .filter_map(|(pubkey, bit)| bit.then(|| pubkey)) + .filter_map(|(pubkey, bit)| bit.then_some(pubkey)) .collect::>(); // Ensure that all signatures are valid. diff --git a/beacon_node/beacon_chain/src/test_utils.rs b/beacon_node/beacon_chain/src/test_utils.rs index f49563b14..d5a888038 100644 --- a/beacon_node/beacon_chain/src/test_utils.rs +++ b/beacon_node/beacon_chain/src/test_utils.rs @@ -1130,7 +1130,7 @@ where selection_proof .is_aggregator::() .expect("should determine aggregator") - .then(|| validator_index) + .then_some(validator_index) })?; let default = SyncCommitteeContribution::from_message( diff --git a/beacon_node/http_api/src/lib.rs b/beacon_node/http_api/src/lib.rs index 312f2a29e..5b4fa5816 100644 --- a/beacon_node/http_api/src/lib.rs +++ b/beacon_node/http_api/src/lib.rs @@ -2531,7 +2531,7 @@ pub fn serve( || matches!(validator_status, ValidatorStatus::Active); // Filter out validators who are not 'active' or 'pending'. - is_active_or_pending.then(|| { + is_active_or_pending.then_some({ ( ProposerPreparationData { validator_index: validator_index as u64, diff --git a/consensus/merkle_proof/src/lib.rs b/consensus/merkle_proof/src/lib.rs index 84f27bdb8..da9b78ff1 100644 --- a/consensus/merkle_proof/src/lib.rs +++ b/consensus/merkle_proof/src/lib.rs @@ -100,9 +100,7 @@ impl MerkleTree { (Leaf(_), Leaf(_)) => return Err(MerkleTreeError::MerkleTreeFull), // There is a right node so insert in right node (Node(_, _, _), Node(_, _, _)) => { - if let Err(e) = right.push_leaf(elem, depth - 1) { - return Err(e); - } + right.push_leaf(elem, depth - 1)?; } // Both branches are zero, insert in left one (Zero(_), Zero(_)) => { diff --git a/consensus/ssz_types/src/fixed_vector.rs b/consensus/ssz_types/src/fixed_vector.rs index e64e76ef4..1ad82a384 100644 --- a/consensus/ssz_types/src/fixed_vector.rs +++ b/consensus/ssz_types/src/fixed_vector.rs @@ -326,7 +326,7 @@ mod test { assert_eq!(fixed[0], 1); assert_eq!(&fixed[0..1], &vec[0..1]); - assert_eq!((&fixed[..]).len(), 8192); + assert_eq!((fixed[..]).len(), 8192); fixed[1] = 3; assert_eq!(fixed[1], 3); diff --git a/consensus/ssz_types/src/variable_list.rs b/consensus/ssz_types/src/variable_list.rs index f23872c87..a342b361e 100644 --- a/consensus/ssz_types/src/variable_list.rs +++ b/consensus/ssz_types/src/variable_list.rs @@ -308,7 +308,7 @@ mod test { assert_eq!(fixed[0], 1); assert_eq!(&fixed[0..1], &vec[0..1]); - assert_eq!((&fixed[..]).len(), 2); + assert_eq!((fixed[..]).len(), 2); fixed[1] = 3; assert_eq!(fixed[1], 3); diff --git a/validator_client/src/preparation_service.rs b/validator_client/src/preparation_service.rs index d4178f2c4..af152545e 100644 --- a/validator_client/src/preparation_service.rs +++ b/validator_client/src/preparation_service.rs @@ -294,7 +294,7 @@ impl PreparationService { proposal_data.fee_recipient.and_then(|fee_recipient| { proposal_data .builder_proposals - .then(|| ValidatorRegistrationKey { + .then_some(ValidatorRegistrationKey { fee_recipient, gas_limit: proposal_data.gas_limit, pubkey,