Fix Rust beta compiler warnings (rustc 1.75.0-beta.1 (782883f60 2023-11-12)) (#4932)

This commit is contained in:
Jimmy Chen 2023-11-18 03:55:11 +11:00 committed by GitHub
parent 68e076d60a
commit 6b63d18420
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 45 additions and 51 deletions

View File

@ -215,7 +215,8 @@ lint:
-A clippy::upper-case-acronyms \ -A clippy::upper-case-acronyms \
-A clippy::vec-init-then-push \ -A clippy::vec-init-then-push \
-A clippy::question-mark \ -A clippy::question-mark \
-A clippy::uninlined-format-args -A clippy::uninlined-format-args \
-A clippy::enum_variant_names
# Lints the code using Clippy and automatically fix some simple compiler warnings. # Lints the code using Clippy and automatically fix some simple compiler warnings.
lint-fix: lint-fix:

View File

@ -18,7 +18,7 @@ use crate::block_verification::{
use crate::block_verification_types::{ use crate::block_verification_types::{
AsBlock, AvailableExecutedBlock, BlockImportData, ExecutedBlock, RpcBlock, AsBlock, AvailableExecutedBlock, BlockImportData, ExecutedBlock, RpcBlock,
}; };
pub use crate::canonical_head::{CanonicalHead, CanonicalHeadRwLock}; pub use crate::canonical_head::CanonicalHead;
use crate::chain_config::ChainConfig; use crate::chain_config::ChainConfig;
use crate::data_availability_checker::{ use crate::data_availability_checker::{
Availability, AvailabilityCheckError, AvailableBlock, DataAvailabilityChecker, Availability, AvailabilityCheckError, AvailableBlock, DataAvailabilityChecker,

View File

@ -93,21 +93,15 @@ impl<E: EthSpec> TryFrom<BuilderBid<E>> for ProvenancedPayload<BlockProposalCont
fn try_from(value: BuilderBid<E>) -> Result<Self, Error> { fn try_from(value: BuilderBid<E>) -> Result<Self, Error> {
let block_proposal_contents = match value { let block_proposal_contents = match value {
BuilderBid::Merge(builder_bid) => BlockProposalContents::Payload { BuilderBid::Merge(builder_bid) => BlockProposalContents::Payload {
payload: ExecutionPayloadHeader::Merge(builder_bid.header) payload: ExecutionPayloadHeader::Merge(builder_bid.header).into(),
.try_into()
.map_err(|_| Error::InvalidPayloadConversion)?,
block_value: builder_bid.value, block_value: builder_bid.value,
}, },
BuilderBid::Capella(builder_bid) => BlockProposalContents::Payload { BuilderBid::Capella(builder_bid) => BlockProposalContents::Payload {
payload: ExecutionPayloadHeader::Capella(builder_bid.header) payload: ExecutionPayloadHeader::Capella(builder_bid.header).into(),
.try_into()
.map_err(|_| Error::InvalidPayloadConversion)?,
block_value: builder_bid.value, block_value: builder_bid.value,
}, },
BuilderBid::Deneb(builder_bid) => BlockProposalContents::PayloadAndBlobs { BuilderBid::Deneb(builder_bid) => BlockProposalContents::PayloadAndBlobs {
payload: ExecutionPayloadHeader::Deneb(builder_bid.header) payload: ExecutionPayloadHeader::Deneb(builder_bid.header).into(),
.try_into()
.map_err(|_| Error::InvalidPayloadConversion)?,
block_value: builder_bid.value, block_value: builder_bid.value,
kzg_commitments: builder_bid.blinded_blobs_bundle.commitments, kzg_commitments: builder_bid.blinded_blobs_bundle.commitments,
blobs: BlobItems::<E>::try_from_blob_roots( blobs: BlobItems::<E>::try_from_blob_roots(

View File

@ -655,14 +655,17 @@ pub fn load_test_blobs_bundle<E: EthSpec>() -> Result<(KzgCommitment, KzgProof,
Ok(( Ok((
commitments commitments
.get(0) .first()
.cloned() .cloned()
.ok_or("commitment missing in test bundle")?, .ok_or("commitment missing in test bundle")?,
proofs proofs
.get(0) .first()
.cloned() .cloned()
.ok_or("proof missing in test bundle")?, .ok_or("proof missing in test bundle")?,
blobs.get(0).cloned().ok_or("blob missing in test bundle")?, blobs
.first()
.cloned()
.ok_or("blob missing in test bundle")?,
)) ))
} }

View File

@ -1,4 +1,4 @@
pub use crate::{common::genesis_deposits, interop::interop_genesis_state}; pub use crate::common::genesis_deposits;
pub use eth1::Config as Eth1Config; pub use eth1::Config as Eth1Config;
use eth1::{DepositLog, Eth1Block, Service as Eth1Service}; use eth1::{DepositLog, Eth1Block, Service as Eth1Service};

View File

@ -569,9 +569,9 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>| { chain: Arc<BeaconChain<T>>| {
task_spawner.blocking_json_task(Priority::P1, move || { task_spawner.blocking_json_task(Priority::P1, move || {
let (root, execution_optimistic, finalized) = state_id.root(&chain)?; let (root, execution_optimistic, finalized) = state_id.root(&chain)?;
Ok(root) Ok(api_types::GenericResponse::from(api_types::RootData::from(
.map(api_types::RootData::from) root,
.map(api_types::GenericResponse::from) )))
.map(|resp| { .map(|resp| {
resp.add_execution_optimistic_finalized(execution_optimistic, finalized) resp.add_execution_optimistic_finalized(execution_optimistic, finalized)
}) })
@ -1940,8 +1940,8 @@ pub fn serve<T: BeaconChainTypes>(
.naive_aggregation_pool .naive_aggregation_pool
.read() .read()
.iter() .iter()
.cloned() .filter(|&att| query_filter(&att.data))
.filter(|att| query_filter(&att.data)), .cloned(),
); );
Ok(api_types::GenericResponse::from(attestations)) Ok(api_types::GenericResponse::from(attestations))
}) })
@ -2318,9 +2318,7 @@ pub fn serve<T: BeaconChainTypes>(
task_spawner.blocking_json_task(Priority::P1, move || { task_spawner.blocking_json_task(Priority::P1, move || {
let (rewards, execution_optimistic, finalized) = let (rewards, execution_optimistic, finalized) =
standard_block_rewards::compute_beacon_block_rewards(chain, block_id)?; standard_block_rewards::compute_beacon_block_rewards(chain, block_id)?;
Ok(rewards) Ok(api_types::GenericResponse::from(rewards)).map(|resp| {
.map(api_types::GenericResponse::from)
.map(|resp| {
resp.add_execution_optimistic_finalized(execution_optimistic, finalized) resp.add_execution_optimistic_finalized(execution_optimistic, finalized)
}) })
}) })
@ -2435,8 +2433,7 @@ pub fn serve<T: BeaconChainTypes>(
let execution_optimistic = let execution_optimistic =
chain.is_optimistic_or_invalid_head().unwrap_or_default(); chain.is_optimistic_or_invalid_head().unwrap_or_default();
Ok(attestation_rewards) Ok(api_types::GenericResponse::from(attestation_rewards))
.map(api_types::GenericResponse::from)
.map(|resp| resp.add_execution_optimistic(execution_optimistic)) .map(|resp| resp.add_execution_optimistic(execution_optimistic))
}) })
}, },
@ -2462,9 +2459,7 @@ pub fn serve<T: BeaconChainTypes>(
chain, block_id, validators, log, chain, block_id, validators, log,
)?; )?;
Ok(rewards) Ok(api_types::GenericResponse::from(rewards)).map(|resp| {
.map(api_types::GenericResponse::from)
.map(|resp| {
resp.add_execution_optimistic_finalized(execution_optimistic, finalized) resp.add_execution_optimistic_finalized(execution_optimistic, finalized)
}) })
}) })

View File

@ -4,8 +4,6 @@ use lighthouse_metrics::TextEncoder;
use lighthouse_network::prometheus_client::encoding::text::encode; use lighthouse_network::prometheus_client::encoding::text::encode;
use malloc_utils::scrape_allocator_metrics; use malloc_utils::scrape_allocator_metrics;
pub use lighthouse_metrics::*;
pub fn gather_prometheus_metrics<T: BeaconChainTypes>( pub fn gather_prometheus_metrics<T: BeaconChainTypes>(
ctx: &Context<T>, ctx: &Context<T>,
) -> std::result::Result<String, String> { ) -> std::result::Result<String, String> {

View File

@ -1,6 +1,6 @@
//! Helper functions and an extension trait for Ethereum 2 ENRs. //! Helper functions and an extension trait for Ethereum 2 ENRs.
pub use discv5::enr::{self, CombinedKey, EnrBuilder}; pub use discv5::enr::{CombinedKey, EnrBuilder};
use super::enr_ext::CombinedKeyExt; use super::enr_ext::CombinedKeyExt;
use super::ENR_FILENAME; use super::ENR_FILENAME;

View File

@ -1489,7 +1489,7 @@ mod tests {
assert!(the_best.is_some()); assert!(the_best.is_some());
// Consistency check // Consistency check
let best_peers = pdb.best_peers_by_status(PeerInfo::is_connected); let best_peers = pdb.best_peers_by_status(PeerInfo::is_connected);
assert_eq!(the_best.unwrap(), best_peers.get(0).unwrap().0); assert_eq!(the_best.unwrap(), best_peers.first().unwrap().0);
} }
#[test] #[test]

View File

@ -378,7 +378,7 @@ fn handle_error<T>(
Ok(None) Ok(None)
} }
} }
_ => Err(err).map_err(RPCError::from), _ => Err(RPCError::from(err)),
} }
} }

View File

@ -224,7 +224,7 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
request_id: PeerRequestId, request_id: PeerRequestId,
request: BlobsByRootRequest, request: BlobsByRootRequest,
) { ) {
let Some(requested_root) = request.blob_ids.get(0).map(|id| id.block_root) else { let Some(requested_root) = request.blob_ids.first().map(|id| id.block_root) else {
// No blob ids requested. // No blob ids requested.
return; return;
}; };

View File

@ -929,7 +929,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// Sort peers prioritizing unrelated peers with less active requests. // Sort peers prioritizing unrelated peers with less active requests.
priorized_peers.sort_unstable(); priorized_peers.sort_unstable();
priorized_peers.get(0).map(|&(_, _, peer)| peer) priorized_peers.first().map(|&(_, _, peer)| peer)
}; };
if let Some(peer) = new_peer { if let Some(peer) = new_peer {

View File

@ -1635,7 +1635,7 @@ mod deneb_only {
self self
} }
fn invalidate_blobs_too_many(mut self) -> Self { fn invalidate_blobs_too_many(mut self) -> Self {
let first_blob = self.blobs.get(0).expect("blob").clone(); let first_blob = self.blobs.first().expect("blob").clone();
self.blobs.push(first_blob); self.blobs.push(first_blob);
self self
} }

View File

@ -885,7 +885,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
.collect::<Vec<_>>(); .collect::<Vec<_>>();
// Sort peers prioritizing unrelated peers with less active requests. // Sort peers prioritizing unrelated peers with less active requests.
priorized_peers.sort_unstable(); priorized_peers.sort_unstable();
priorized_peers.get(0).map(|&(_, _, peer)| peer) priorized_peers.first().map(|&(_, _, peer)| peer)
}; };
if let Some(peer) = new_peer { if let Some(peer) = new_peer {

View File

@ -2,8 +2,6 @@ use super::{ManualSlotClock, SlotClock};
use std::time::{Duration, SystemTime, UNIX_EPOCH}; use std::time::{Duration, SystemTime, UNIX_EPOCH};
use types::Slot; use types::Slot;
pub use std::time::SystemTimeError;
/// Determines the present slot based upon the present system time. /// Determines the present slot based upon the present system time.
#[derive(Clone)] #[derive(Clone)]
pub struct SystemTimeSlotClock { pub struct SystemTimeSlotClock {

View File

@ -250,7 +250,7 @@ impl MerkleTree {
if deposit_count == (0x1 << level) { if deposit_count == (0x1 << level) {
return Ok(MerkleTree::Finalized( return Ok(MerkleTree::Finalized(
*finalized_branch *finalized_branch
.get(0) .first()
.ok_or(MerkleTreeError::PleaseNotifyTheDevs)?, .ok_or(MerkleTreeError::PleaseNotifyTheDevs)?,
)); ));
} }

View File

@ -25,11 +25,11 @@ pub struct SyncAggregatorSelectionData {
pub subcommittee_index: u64, pub subcommittee_index: u64,
} }
impl SignedRoot for SyncAggregatorSelectionData {}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
ssz_and_tree_hash_tests!(SyncAggregatorSelectionData); ssz_and_tree_hash_tests!(SyncAggregatorSelectionData);
} }
impl SignedRoot for SyncAggregatorSelectionData {}

View File

@ -127,7 +127,7 @@ vectors_and_tests!(
ExitTest { ExitTest {
block_modifier: Box::new(|_, block| { block_modifier: Box::new(|_, block| {
// Duplicate the exit // Duplicate the exit
let exit = block.body().voluntary_exits().get(0).unwrap().clone(); let exit = block.body().voluntary_exits().first().unwrap().clone();
block.body_mut().voluntary_exits_mut().push(exit).unwrap(); block.body_mut().voluntary_exits_mut().push(exit).unwrap();
}), }),
expected: Err(BlockProcessingError::ExitInvalid { expected: Err(BlockProcessingError::ExitInvalid {

View File

@ -17,7 +17,7 @@ pub use config::Config;
pub use database::{ pub use database::{
get_blockprint_by_root, get_blockprint_by_slot, get_highest_blockprint, get_lowest_blockprint, get_blockprint_by_root, get_blockprint_by_slot, get_highest_blockprint, get_lowest_blockprint,
get_unknown_blockprint, get_validators_clients_at_slot, insert_batch_blockprint, get_unknown_blockprint, get_validators_clients_at_slot, insert_batch_blockprint,
list_consensus_clients, WatchBlockprint, WatchBlockprint,
}; };
pub use server::blockprint_routes; pub use server::blockprint_routes;

View File

@ -26,24 +26,29 @@ pub use self::error::Error;
pub use self::models::{WatchBeaconBlock, WatchCanonicalSlot, WatchProposerInfo, WatchValidator}; pub use self::models::{WatchBeaconBlock, WatchCanonicalSlot, WatchProposerInfo, WatchValidator};
pub use self::watch_types::{WatchHash, WatchPK, WatchSlot}; pub use self::watch_types::{WatchHash, WatchPK, WatchSlot};
// Clippy has false positives on these re-exports from Rust 1.75.0-beta.1.
#[allow(unused_imports)]
pub use crate::block_rewards::{ pub use crate::block_rewards::{
get_block_rewards_by_root, get_block_rewards_by_slot, get_highest_block_rewards, get_block_rewards_by_root, get_block_rewards_by_slot, get_highest_block_rewards,
get_lowest_block_rewards, get_unknown_block_rewards, insert_batch_block_rewards, get_lowest_block_rewards, get_unknown_block_rewards, insert_batch_block_rewards,
WatchBlockRewards, WatchBlockRewards,
}; };
#[allow(unused_imports)]
pub use crate::block_packing::{ pub use crate::block_packing::{
get_block_packing_by_root, get_block_packing_by_slot, get_highest_block_packing, get_block_packing_by_root, get_block_packing_by_slot, get_highest_block_packing,
get_lowest_block_packing, get_unknown_block_packing, insert_batch_block_packing, get_lowest_block_packing, get_unknown_block_packing, insert_batch_block_packing,
WatchBlockPacking, WatchBlockPacking,
}; };
#[allow(unused_imports)]
pub use crate::suboptimal_attestations::{ pub use crate::suboptimal_attestations::{
get_all_suboptimal_attestations_for_epoch, get_attestation_by_index, get_attestation_by_pubkey, get_all_suboptimal_attestations_for_epoch, get_attestation_by_index, get_attestation_by_pubkey,
get_highest_attestation, get_lowest_attestation, insert_batch_suboptimal_attestations, get_highest_attestation, get_lowest_attestation, insert_batch_suboptimal_attestations,
WatchAttestation, WatchSuboptimalAttestation, WatchAttestation, WatchSuboptimalAttestation,
}; };
#[allow(unused_imports)]
pub use crate::blockprint::{ pub use crate::blockprint::{
get_blockprint_by_root, get_blockprint_by_slot, get_highest_blockprint, get_lowest_blockprint, get_blockprint_by_root, get_blockprint_by_slot, get_highest_blockprint, get_lowest_blockprint,
get_unknown_blockprint, get_validators_clients_at_slot, insert_batch_blockprint, get_unknown_blockprint, get_validators_clients_at_slot, insert_batch_blockprint,