Skip to content

Commit

Permalink
Update Rust toolchain to 1.77.2, pass or suppress lints, use new feat…
Browse files Browse the repository at this point in the history
…ures

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.
  • Loading branch information
weekday-grandine-io committed Apr 12, 2024
1 parent 171f955 commit e62928c
Show file tree
Hide file tree
Showing 27 changed files with 96 additions and 106 deletions.
93 changes: 49 additions & 44 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -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 }
Expand Down Expand Up @@ -224,7 +229,7 @@ semicolon_if_nothing_returned = { level = 'allow', priority = 1 }
# - <https://github.com/rust-lang/rust-clippy/issues/9072>
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 <https://github.com/rust-lang/rust-clippy/issues/10413>.
significant_drop_tightening = { level = 'allow', priority = 1 }

Expand Down
2 changes: 1 addition & 1 deletion benches/benches/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/issues/61415>.
// We work around that by using `PublicKeyBytes` and `SignatureBytes` instead.

Expand Down
1 change: 1 addition & 0 deletions benches/benches/lookup_in_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions eip_2335/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {},
}

Expand Down
2 changes: 2 additions & 0 deletions eth1_api/src/deposit_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ impl TryFrom<Log> 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,
Expand Down
4 changes: 2 additions & 2 deletions fork_choice_control/src/mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 2 additions & 9 deletions fork_choice_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,10 @@ impl<P: Preset> Store<P> {

#[must_use]
pub fn unfinalized_chain_link_mut(&mut self, block_root: H256) -> Option<&mut ChainLink<P>> {
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)
}
Expand Down Expand Up @@ -2147,10 +2143,7 @@ impl<P: Preset> Store<P> {
.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() {
Expand Down
9 changes: 3 additions & 6 deletions grandine/src/grandine_args.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -1389,7 +1386,7 @@ fn headers_to_allow_origin(allowed_origins: Vec<HeaderValue>) -> Option<AllowOri

#[cfg(test)]
mod tests {
use std::net::{Ipv4Addr, SocketAddr};
use core::net::{Ipv4Addr, SocketAddr};

use tempfile::NamedTempFile;

Expand Down
4 changes: 2 additions & 2 deletions grandine/src/grandine_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::time::Duration;
use std::{net::SocketAddr, path::PathBuf, sync::Arc};
use core::{net::SocketAddr, time::Duration};
use std::{path::PathBuf, sync::Arc};

use builder_api::BuilderConfig;
use eth1_api::AuthOptions;
Expand Down
4 changes: 2 additions & 2 deletions grandine/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::{future::Future, panic::AssertUnwindSafe, pin::pin};
use core::{future::Future, net::SocketAddr, panic::AssertUnwindSafe, pin::pin};
use std::{
net::{SocketAddr, TcpListener, UdpSocket},
net::{TcpListener, UdpSocket},
path::PathBuf,
process::ExitCode,
sync::Arc,
Expand Down
4 changes: 2 additions & 2 deletions http_api/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::future::Future;
use std::{net::Ipv4Addr, sync::Arc};
use core::{future::Future, net::Ipv4Addr};
use std::sync::Arc;

use anyhow::Result;
use bls::{PublicKeyBytes, SecretKey};
Expand Down
2 changes: 1 addition & 1 deletion http_api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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<Item = &dyn StdError> {
let mut error: Option<&dyn StdError> = Some(self);

Expand Down
6 changes: 4 additions & 2 deletions http_api/src/http_api_config.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
3 changes: 2 additions & 1 deletion http_api/src/task.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion http_api_utils/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &dyn StdError> {
let mut error: Option<&dyn StdError> = Some(self);

Expand Down
4 changes: 2 additions & 2 deletions http_api_utils/src/logging.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion http_api_utils/src/middleware.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
6 changes: 3 additions & 3 deletions metrics/src/server.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
4 changes: 1 addition & 3 deletions p2p/src/sync_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,7 @@ impl SyncManager {
}

pub fn random_peer(&self) -> Option<PeerId> {
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()
Expand Down
2 changes: 1 addition & 1 deletion p2p/src/upnp.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = 'stable-2024-02-08'
channel = 'stable-2024-04-09'
profile = 'minimal'
components = ['clippy', 'rustfmt']
4 changes: 0 additions & 4 deletions signer/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/rust-lang/rust/pull/102287/>.
// There seems to be no issue about this in <https://github.com/rust-lang/rust-clippy>.
#[must_use]
pub fn keys(&self) -> impl ExactSizeIterator<Item = &PublicKeyBytes> {
self.sign_methods.keys()
}
Expand Down
7 changes: 2 additions & 5 deletions snapshot_test_utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion ssz/src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl<D: ArrayLength<H256>> MerkleTree<D> {
// ```
// See <https://oeis.org/A003817>.
//
// `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();
Expand Down
11 changes: 5 additions & 6 deletions validator/src/api.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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<Item = &dyn StdError> {
let mut error: Option<&dyn StdError> = Some(self);

Expand Down
3 changes: 1 addition & 2 deletions validator/src/own_beacon_committee_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ impl OwnBeaconCommitteeSubscriptions {
) -> Result<Vec<BeaconCommitteeSubscription>> {
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![]);
}
Expand Down
Loading

0 comments on commit e62928c

Please sign in to comment.