From e62928c4f00e3462bd60268585b15e13a1187968 Mon Sep 17 00:00:00 2001 From: weekday Date: Fri, 12 Apr 2024 03:36:21 +0000 Subject: [PATCH] Update Rust toolchain to 1.77.2, pass or suppress lints, use new features core::mem::offset_of! was stabilized in Rust 1.77.0, but there is no equivalent to memoffset::span_of!. The ranges are easy to write manually, but that would risk introducing bugs unless we added more tests. It may be better to specify offsets explicitly instead of having a struct just to calculate them. None of that belongs in a toolchain update. None of the slice methods stabilized in Rust 1.77.0 appear to be useful. The shuffling crate needs [T]::as_chunks_mut and [T]::as_rchunks_mut, which are still unstable. --- Cargo.toml | 93 ++++++++++--------- benches/benches/hashing.rs | 2 +- benches/benches/lookup_in_collection.rs | 1 + eip_2335/src/lib.rs | 2 + eth1_api/src/deposit_event.rs | 2 + fork_choice_control/src/mutator.rs | 4 +- fork_choice_store/src/store.rs | 11 +-- grandine/src/grandine_args.rs | 9 +- grandine/src/grandine_config.rs | 4 +- grandine/src/main.rs | 4 +- http_api/src/context.rs | 4 +- http_api/src/error.rs | 2 +- http_api/src/http_api_config.rs | 6 +- http_api/src/task.rs | 3 +- http_api_utils/src/error.rs | 2 +- http_api_utils/src/logging.rs | 4 +- http_api_utils/src/middleware.rs | 3 +- metrics/src/server.rs | 6 +- p2p/src/sync_manager.rs | 4 +- p2p/src/upnp.rs | 2 +- rust-toolchain.toml | 2 +- signer/src/signer.rs | 4 - snapshot_test_utils/src/lib.rs | 7 +- ssz/src/merkle_tree.rs | 2 +- validator/src/api.rs | 11 +-- .../src/own_beacon_committee_subscriptions.rs | 3 +- validator/src/validator.rs | 5 +- 27 files changed, 96 insertions(+), 106 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index af209238..9dd2fa0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -138,6 +138,10 @@ wildcard_dependencies = 'warn' # Setting it to deny (as opposed to forbid) makes no sense. # `core::mem::forget` is impossible to use by mistake. # +# - `clippy::single_call_fn`. +# It's unidiomatic and conflicts with lints like `clippy::too_many_lines`. +# Public functions are not exempt from it as of Rust 1.77.2. +# # - `clippy::std_instead_of_alloc` # It would require adding `extern crate alloc;` everywhere. # @@ -146,50 +150,51 @@ wildcard_dependencies = 'warn' # # - `clippy::unimplemented` # It's useful to leave some trait methods unimplemented. -alloc_instead_of_core = 'warn' -allow_attributes = 'warn' -allow_attributes_without_reason = 'warn' -assertions_on_result_states = 'warn' -clone_on_ref_ptr = 'warn' -dbg_macro = 'warn' -decimal_literal_representation = 'warn' -empty_drop = 'warn' -empty_structs_with_brackets = 'warn' -filetype_is_file = 'warn' -float_arithmetic = 'warn' -float_cmp_const = 'warn' -format_push_string = 'warn' -get_unwrap = 'warn' -host_endian_bytes = 'warn' -if_then_some_else_none = 'warn' -lossy_float_literal = 'warn' -missing_asserts_for_indexing = 'warn' -mixed_read_write_in_expression = 'warn' -multiple_inherent_impl = 'warn' -mutex_atomic = 'warn' -needless_raw_strings = 'warn' -partial_pub_fields = 'warn' -print_stderr = 'warn' -print_stdout = 'warn' -pub_without_shorthand = 'warn' -rc_buffer = 'warn' -rc_mutex = 'warn' -redundant_type_annotations = 'warn' -rest_pat_in_fully_bound_structs = 'warn' -same_name_method = 'warn' -semicolon_inside_block = 'warn' -std_instead_of_core = 'warn' -str_to_string = 'warn' -string_add = 'warn' -string_lit_chars_any = 'warn' -string_slice = 'warn' -string_to_string = 'warn' -todo = 'warn' +alloc_instead_of_core = 'warn' +allow_attributes = 'warn' +allow_attributes_without_reason = 'warn' +assertions_on_result_states = 'warn' +clone_on_ref_ptr = 'warn' +dbg_macro = 'warn' +decimal_literal_representation = 'warn' +empty_drop = 'warn' +empty_enum_variants_with_brackets = 'warn' +empty_structs_with_brackets = 'warn' +filetype_is_file = 'warn' +float_arithmetic = 'warn' +float_cmp_const = 'warn' +format_push_string = 'warn' +get_unwrap = 'warn' +host_endian_bytes = 'warn' +if_then_some_else_none = 'warn' +lossy_float_literal = 'warn' +missing_asserts_for_indexing = 'warn' +mixed_read_write_in_expression = 'warn' +multiple_inherent_impl = 'warn' +mutex_atomic = 'warn' +needless_raw_strings = 'warn' +partial_pub_fields = 'warn' +print_stderr = 'warn' +print_stdout = 'warn' +pub_without_shorthand = 'warn' +rc_buffer = 'warn' +rc_mutex = 'warn' +redundant_type_annotations = 'warn' +rest_pat_in_fully_bound_structs = 'warn' +same_name_method = 'warn' +semicolon_inside_block = 'warn' +std_instead_of_core = 'warn' +str_to_string = 'warn' +string_add = 'warn' +string_lit_chars_any = 'warn' +string_slice = 'warn' +string_to_string = 'warn' +todo = 'warn' # Enable `clippy::undocumented_unsafe_blocks` in case we ever change our stance on unsafe code. -undocumented_unsafe_blocks = 'warn' -unnecessary_self_imports = 'warn' -unwrap_used = 'warn' -verbose_file_reads = 'warn' +undocumented_unsafe_blocks = 'warn' +unnecessary_self_imports = 'warn' +unwrap_used = 'warn' +verbose_file_reads = 'warn' # These are almost never helpful. assertions_on_constants = { level = 'allow', priority = 1 } @@ -224,7 +229,7 @@ semicolon_if_nothing_returned = { level = 'allow', priority = 1 } # - significant_drop_in_scrutinee = { level = 'allow', priority = 1 } -# `clippy::significant_drop_tightening` produces only false positives. +# `clippy::significant_drop_tightening` often produces false positives. # See . significant_drop_tightening = { level = 'allow', priority = 1 } diff --git a/benches/benches/hashing.rs b/benches/benches/hashing.rs index 2e9ee256..ad727b6b 100644 --- a/benches/benches/hashing.rs +++ b/benches/benches/hashing.rs @@ -89,7 +89,7 @@ fn main() { criterion.final_summary(); } -// Arrays of arbitrary length do not implement `Default` as of Rust 1.76.0. +// Arrays of arbitrary length do not implement `Default` as of Rust 1.77.2. // See . // We work around that by using `PublicKeyBytes` and `SignatureBytes` instead. diff --git a/benches/benches/lookup_in_collection.rs b/benches/benches/lookup_in_collection.rs index f7d7f52b..b0d64797 100644 --- a/benches/benches/lookup_in_collection.rs +++ b/benches/benches/lookup_in_collection.rs @@ -38,6 +38,7 @@ struct Small; // This is a new type rather than an alias to make the output of `tynm::type_name` look better. #[derive(Clone, Copy, Default)] +#[allow(dead_code)] struct Large([usize; 8]); // Criterion macros only add confusion. diff --git a/eip_2335/src/lib.rs b/eip_2335/src/lib.rs index c4f861ee..531da296 100644 --- a/eip_2335/src/lib.rs +++ b/eip_2335/src/lib.rs @@ -252,6 +252,8 @@ impl Kdf { content = "params" )] enum Checksum { + // The empty braces affect the generated Serde impls. + #[allow(clippy::empty_enum_variants_with_brackets)] Sha256 {}, } diff --git a/eth1_api/src/deposit_event.rs b/eth1_api/src/deposit_event.rs index 7e951f28..2ea19709 100644 --- a/eth1_api/src/deposit_event.rs +++ b/eth1_api/src/deposit_event.rs @@ -114,6 +114,8 @@ impl TryFrom for DepositEvent { ensure!(log_data.len() == Self::LENGTH, Error::WrongLength { log }); + // `core::mem::offset_of!` was stabilized in Rust 1.77.0, + // but there is no equivalent to `memoffset::span_of!` in the standard library. let ( pubkey_range, withdrawal_credentials_range, diff --git a/fork_choice_control/src/mutator.rs b/fork_choice_control/src/mutator.rs index b079bdd5..386bcde4 100644 --- a/fork_choice_control/src/mutator.rs +++ b/fork_choice_control/src/mutator.rs @@ -2007,7 +2007,7 @@ where let mut gossip_ids = vec![]; - // Use `drain_filter_polyfill` because `Vec::extract_if` is not stable as of Rust 1.76.0. + // Use `drain_filter_polyfill` because `Vec::extract_if` is not stable as of Rust 1.77.2. self.delayed_until_block.retain(|_, delayed| { let Delayed { blocks, @@ -2081,7 +2081,7 @@ where let mut gossip_ids = vec![]; - // Use `HashMap::retain` because `HashMap::extract_if` is not stable as of Rust 1.76.0. + // Use `HashMap::retain` because `HashMap::extract_if` is not stable as of Rust 1.77.2. self.waiting_for_checkpoint_states .retain(|target, waiting| { let prune = target.epoch < finalized_epoch; diff --git a/fork_choice_store/src/store.rs b/fork_choice_store/src/store.rs index 1076ec8e..dc87ffa5 100644 --- a/fork_choice_store/src/store.rs +++ b/fork_choice_store/src/store.rs @@ -506,14 +506,10 @@ impl Store

{ #[must_use] pub fn unfinalized_chain_link_mut(&mut self, block_root: H256) -> Option<&mut ChainLink

> { - let Some(location) = self.unfinalized_locations.get(&block_root) else { - return None; - }; - let Location { segment_id, position, - } = location; + } = self.unfinalized_locations.get(&block_root)?; Some(&mut self.unfinalized[segment_id][*position].chain_link) } @@ -2147,10 +2143,7 @@ impl Store

{ .collect_vec(); // Updating the finalized checkpoint does not always result in new finalized blocks. - let Some(locations) = locations_from_newest_to_root.split_first() else { - return None; - }; - + let locations = locations_from_newest_to_root.split_first()?; let (partially_finalized_location, completely_finalized_locations) = locations; for completely_finalized_location in completely_finalized_locations.iter().rev() { diff --git a/grandine/src/grandine_args.rs b/grandine/src/grandine_args.rs index 87437130..9dc05d8c 100644 --- a/grandine/src/grandine_args.rs +++ b/grandine/src/grandine_args.rs @@ -1,14 +1,11 @@ use core::{ fmt::Display, + net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, num::{NonZeroU16, NonZeroU64}, ops::Not as _, time::Duration, }; -use std::{ - net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, - path::PathBuf, - sync::Arc, -}; +use std::{path::PathBuf, sync::Arc}; use anyhow::{ensure, Result}; use bls::PublicKeyBytes; @@ -1389,7 +1386,7 @@ fn headers_to_allow_origin(allowed_origins: Vec) -> Option impl Iterator { let mut error: Option<&dyn StdError> = Some(self); diff --git a/http_api/src/http_api_config.rs b/http_api/src/http_api_config.rs index b79fec34..0369a81c 100644 --- a/http_api/src/http_api_config.rs +++ b/http_api/src/http_api_config.rs @@ -1,5 +1,7 @@ -use core::time::Duration; -use std::net::{IpAddr, Ipv4Addr, SocketAddr}; +use core::{ + net::{IpAddr, Ipv4Addr, SocketAddr}, + time::Duration, +}; use educe::Educe; use hyper::{server::conn::AddrIncoming, Result}; diff --git a/http_api/src/task.rs b/http_api/src/task.rs index c9337d97..a1beb269 100644 --- a/http_api/src/task.rs +++ b/http_api/src/task.rs @@ -1,4 +1,5 @@ -use std::{collections::HashSet, net::SocketAddr, sync::Arc}; +use core::net::SocketAddr; +use std::{collections::HashSet, sync::Arc}; use anyhow::Result; use axum::{Router, Server}; diff --git a/http_api_utils/src/error.rs b/http_api_utils/src/error.rs index ec9e8473..a131bd56 100644 --- a/http_api_utils/src/error.rs +++ b/http_api_utils/src/error.rs @@ -37,7 +37,7 @@ impl Error { self.sources().format(": ") } - // `StdError::sources` is not stable as of Rust 1.76.0. + // `StdError::sources` is not stable as of Rust 1.77.2. fn sources(&self) -> impl Iterator { let mut error: Option<&dyn StdError> = Some(self); diff --git a/http_api_utils/src/logging.rs b/http_api_utils/src/logging.rs index 2bfc3123..4770ef31 100644 --- a/http_api_utils/src/logging.rs +++ b/http_api_utils/src/logging.rs @@ -1,5 +1,5 @@ -use core::time::Duration; -use std::{net::SocketAddr, sync::Arc}; +use core::{net::SocketAddr, time::Duration}; +use std::sync::Arc; use axum::{ body::Body, diff --git a/http_api_utils/src/middleware.rs b/http_api_utils/src/middleware.rs index 010917b7..bdd2f863 100644 --- a/http_api_utils/src/middleware.rs +++ b/http_api_utils/src/middleware.rs @@ -1,4 +1,5 @@ -use std::{error::Error as StdError, net::SocketAddr}; +use core::net::SocketAddr; +use std::error::Error as StdError; use axum::{ body::{Body, Bytes, HttpBody}, diff --git a/metrics/src/server.rs b/metrics/src/server.rs index ac246470..d02553f6 100644 --- a/metrics/src/server.rs +++ b/metrics/src/server.rs @@ -1,10 +1,10 @@ #![allow(clippy::unused_async)] -use core::time::Duration; -use std::{ +use core::{ net::{IpAddr, SocketAddr}, - sync::Arc, + time::Duration, }; +use std::sync::Arc; use anyhow::{anyhow, Error as AnyhowError, Result}; use axum::{ diff --git a/p2p/src/sync_manager.rs b/p2p/src/sync_manager.rs index b1518432..6a552091 100644 --- a/p2p/src/sync_manager.rs +++ b/p2p/src/sync_manager.rs @@ -391,9 +391,7 @@ impl SyncManager { } pub fn random_peer(&self) -> Option { - let Some(chain_id) = self.chain_with_max_peer_count() else { - return None; - }; + let chain_id = self.chain_with_max_peer_count()?; self.peers .iter() diff --git a/p2p/src/upnp.rs b/p2p/src/upnp.rs index 547d0eba..658aec9e 100644 --- a/p2p/src/upnp.rs +++ b/p2p/src/upnp.rs @@ -1,4 +1,4 @@ -use std::net::{IpAddr, SocketAddr, SocketAddrV4}; +use core::net::{IpAddr, SocketAddr, SocketAddrV4}; use anyhow::{bail, Result}; use eth2_libp2p::{service::Network as Service, NetworkConfig}; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d41a90d5..b4700042 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = 'stable-2024-02-08' +channel = 'stable-2024-04-09' profile = 'minimal' components = ['clippy', 'rustfmt'] diff --git a/signer/src/signer.rs b/signer/src/signer.rs index 808b721e..981b5b2d 100644 --- a/signer/src/signer.rs +++ b/signer/src/signer.rs @@ -131,10 +131,6 @@ impl Snapshot { self.sign_methods.is_empty() } - // The `#[must_use]` is redundant starting with Rust 1.66.0, but Clippy hasn't caught up yet. - // See . - // There seems to be no issue about this in . - #[must_use] pub fn keys(&self) -> impl ExactSizeIterator { self.sign_methods.keys() } diff --git a/snapshot_test_utils/src/lib.rs b/snapshot_test_utils/src/lib.rs index da49bc14..50aeeaa5 100644 --- a/snapshot_test_utils/src/lib.rs +++ b/snapshot_test_utils/src/lib.rs @@ -1,8 +1,5 @@ -use core::ops::Range; -use std::{ - net::SocketAddr, - path::{Path, PathBuf}, -}; +use core::{net::SocketAddr, ops::Range}; +use std::path::{Path, PathBuf}; use anyhow::{bail, ensure, Context as _, Error, Result}; use assert_json_diff::{CompareMode, Config as CompareConfig}; diff --git a/ssz/src/merkle_tree.rs b/ssz/src/merkle_tree.rs index 1d295bc1..df927acf 100644 --- a/ssz/src/merkle_tree.rs +++ b/ssz/src/merkle_tree.rs @@ -237,7 +237,7 @@ impl> MerkleTree { // ``` // See . // - // `usize::saturating_shr` does not exist as of Rust 1.76.0. + // `usize::saturating_shr` does not exist as of Rust 1.77.2. let filled_left_subtree = usize::MAX .checked_shr(chunk_indices.start.leading_ones()) .unwrap_or_default(); diff --git a/validator/src/api.rs b/validator/src/api.rs index fe8b8da7..101ca9ef 100644 --- a/validator/src/api.rs +++ b/validator/src/api.rs @@ -1,10 +1,9 @@ -use core::{fmt::Display, time::Duration}; -use std::{ - error::Error as StdError, +use core::{ + fmt::Display, net::{IpAddr, Ipv4Addr, SocketAddr}, - path::Path, - sync::Arc, + time::Duration, }; +use std::{error::Error as StdError, path::Path, sync::Arc}; use anyhow::{Error as AnyhowError, Result}; use axum::{ @@ -134,7 +133,7 @@ impl Error { self.sources().format(": ") } - // `StdError::sources` is not stable as of Rust 1.76.0. + // `StdError::sources` is not stable as of Rust 1.77.2. fn sources(&self) -> impl Iterator { let mut error: Option<&dyn StdError> = Some(self); diff --git a/validator/src/own_beacon_committee_subscriptions.rs b/validator/src/own_beacon_committee_subscriptions.rs index 7e349b4f..cc26e84c 100644 --- a/validator/src/own_beacon_committee_subscriptions.rs +++ b/validator/src/own_beacon_committee_subscriptions.rs @@ -22,8 +22,7 @@ impl OwnBeaconCommitteeSubscriptions { ) -> Result> { if self .latest_computed_epoch - .map(|computed_epoch| computed_epoch >= epoch) - .unwrap_or_default() + .is_some_and(|computed_epoch| computed_epoch >= epoch) { return Ok(vec![]); } diff --git a/validator/src/validator.rs b/validator/src/validator.rs index 10f26d52..2e010b7f 100644 --- a/validator/src/validator.rs +++ b/validator/src/validator.rs @@ -3053,10 +3053,7 @@ impl Validator { &mut self, block: &SignedBlindedBeaconBlock

, ) -> Option, P>> { - let Some(builder_api) = &self.builder_api else { - return None; - }; - + let builder_api = self.builder_api.as_deref()?; let current_slot = self.controller.slot(); let head_block_root = self.controller.head_block_root().value;