chore: bump rust to edition 2024#18692
Conversation
56a4eb9 to
076d211
Compare
…ss-let-if-seq clippy warning Refactored the backfill threshold calculation logic to eliminate a `let mut` variable that was immediately reassigned. Combined the conditions into a single if-else chain to improve readability and satisfy the `useless-let-if-seq` clippy lint. This change maintains the same logic flow but avoids the pattern that triggers the clippy warning when upgrading to Rust 2024 edition.
d6fa538 to
992ef43
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR bumps the Rust edition from 2021 to 2024 across the entire Reth codebase. The key changes involve adopting new Rust 2024 syntax features, particularly the chained let patterns in conditional statements, updating configuration files, and making necessary adjustments for compatibility.
- Adoption of Rust 2024 edition syntax, primarily chained
letpatterns inif letstatements - Updates to configuration files including
Cargo.toml,rustfmt.toml, and various example manifests - Safety-related changes to
unsafefunction calls and environment variable usage
Reviewed Changes
Copilot reviewed 109 out of 113 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| Cargo.toml | Updates edition to 2024 and adds rust_2024_incompatible_pat warning |
| rustfmt.toml | Sets style_edition to 2021 for consistent formatting |
| examples/ | Updates Cargo.toml files to use edition 2024 |
| crates/ | Widespread adoption of Rust 2024 chained let patterns and unsafe call syntax |
Files not reviewed (1)
- Cargo.lock: Language not supported
Comments suppressed due to low confidence (3)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
CodSpeed Performance ReportMerging #18692 will not alter performanceComparing Summary
|
Rust 2024's stricter match ergonomics don't allow binding modifiers (ref mut) in or-patterns when the default binding mode is not 'move'. Split the or-pattern into separate match arms to comply with Rust 2024.
The key insight is that ref mut is: - Forbidden when matching &mut T (default binding mode is not move) - Allowed when matching T (default binding mode is move) Split the macro into two patterns: - For &mut self: match without ref mut, rely on auto-deref - For owned self: use ref mut in or-pattern (allowed in Rust 2024) Also updated macro invocations to distinguish the cases: - set_ methods: set_value!(&mut self => field) - with_ methods: set_value!(self => field)
Clippy complained about the mutable variable pattern. Refactored to: 1. First determine which block number to use (downloaded > buffered > target) 2. Then compute the threshold check once This maintains the same logic priority: downloaded finalized block takes precedence, then buffered finalized, then target block number.
The logic must check in this specific order: 1. First check buffered finalized OR use target_block_number 2. Then potentially override with downloaded_block if it matches Previous attempts incorrectly checked downloaded_block first, changing the precedence. This restores the exact original behavior where the downloaded block can override the initial value.
- error: `if _ { .. } else { .. }` is an expression
--> crates/engine/tree/src/tree/mod.rs:2041:9
|
2041 | / let mut exceeds_backfill_threshold = if let Some(buffered_finalized) = sync_target_state
2042 | | .as_ref()
2043 | | .and_then(|state| self.state.buffer.block(&state.finalized_block_hash))
... |
2060 | | self.exceeds_backfill_run_threshold(canonical_tip_num, downloaded_block.number);
2061 | | }
| |_________^
|
= note: you might not need `mut` at all
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_let_if_seq
= note: `-D clippy::useless-let-if-seq` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::useless_let_if_seq)]`
help: it is more idiomatic to write
|
2041 ~ let <mut> exceeds_backfill_threshold = if let (Some(downloaded_block), Some(ref state)) = (downloaded_block, sync_target_state) &&
2042 + downloaded_block.hash == state.finalized_block_hash { self.exceeds_backfill_run_threshold(canonical_tip_num, downloaded_block.number) } else { if let Some(buffered_finalized) = sync_target_state
2043 + .as_ref()
2044 + .and_then(|state| self.state.buffer.block(&state.finalized_block_hash))
2045 + {
2046 + // if we have buffered the finalized block, we should check how far
2047 + // we're off
2048 + self.exceeds_backfill_run_threshold(canonical_tip_num, buffered_finalized.number())
2049 + } else {
2050 + // check if the distance exceeds the threshold for backfill sync
2051 + self.exceeds_backfill_run_threshold(canonical_tip_num, target_block_number)
2052 + } };
|
error: `if _ { .. } else { .. }` is an expression
--> crates/engine/tree/src/tree/mod.rs:2041:9
|
2041 | / let mut exceeds_backfill_threshold = if let Some(buffered_finalized) = sync_target_state
2042 | | .as_ref()
2043 | | .and_then(|state| self.state.buffer.block(&state.finalized_block_hash))
... |
2060 | | self.exceeds_backfill_run_threshold(canonical_tip_num, downloaded_block.number);
2061 | | }
| |_________^
|
= note: you might not need `mut` at all
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_let_if_seq
= note: `-D clippy::useless-let-if-seq` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::useless_let_if_seq)]`
help: it is more idiomatic to write
|
2041 ~ let <mut> exceeds_backfill_threshold = if let (Some(downloaded_block), Some(ref state)) = (downloaded_block, sync_target_state) &&
2042 + downloaded_block.hash == state.finalized_block_hash { self.exceeds_backfill_run_threshold(canonical_tip_num, downloaded_block.number) } else { if let Some(buffered_finalized) = sync_target_state
2043 + .as_ref()
2044 + .and_then(|state| self.state.buffer.block(&state.finalized_block_hash))
2045 + {
2046 + // if we have buffered the finalized block, we should check how far
2047 + // we're off
2048 + self.exceeds_backfill_run_threshold(canonical_tip_num, buffered_finalized.number())
2049 + } else {
2050 + // check if the distance exceeds the threshold for backfill sync
2051 + self.exceeds_backfill_run_threshold(canonical_tip_num, target_block_number)
2052 + } };
|
Updated the backfill threshold logic to utilize a match expression instead of an if-let statement. This change improves readability and adheres to idiomatic Rust practices, addressing clippy warnings regarding unnecessary mutable variables.
crates/engine/tree/src/tree/mod.rs
Outdated
|
|
||
| // check if the downloaded block is the tracked finalized block | ||
| let mut exceeds_backfill_threshold = if let Some(buffered_finalized) = sync_target_state | ||
| let mut exceeds_backfill_threshold = match sync_target_state |
There was a problem hiding this comment.
refactored the logic here, because clippy was giving a hard time with
2041 ~ let <mut> exceeds_backfill_threshold = if let (Some(downloaded_block), Some(ref state)) = (downloaded_block, sync_target_state) &&
2042 + downloaded_block.hash == state.finalized_block_hash { self.exceeds_backfill_run_threshold(canonical_tip_num, downloaded_block.number) } else { if let Some(buffered_finalized) = sync_target_state
2043 + .as_ref()
2044 + .and_then(|state| self.state.buffer.block(&state.finalized_block_hash))
2045 + {
2046 + // if we have buffered the finalized block, we should check how far
2047 + // we're off
2048 + self.exceeds_backfill_run_threshold(canonical_tip_num, buffered_finalized.number())
2049 + } else {
2050 + // check if the distance exceeds the threshold for backfill sync
2051 + self.exceeds_backfill_run_threshold(canonical_tip_num, target_block_number)
2052 + } };There was a problem hiding this comment.
this match is equivalent so lgtm
Updated the backfill threshold logic to use a match expression, enhancing clarity and adhering to idiomatic Rust practices. This change addresses previous clippy warnings regarding mutable variables and maintains the same logic precedence for determining the block number.
* dev: (166 commits) chore: bump 1.8.3 (paradigmxyz#19379) chore: bump alloy-evm 0.21.3 chore: bump alloy 1.0.37 (paradigmxyz#18795) chore: bump version to 1.8.2 (paradigmxyz#18792) fix(rpc/engine): check osaka in getBlobsV1 (paradigmxyz#18669) fix: remove cancun check (paradigmxyz#18787) fix(rpc): fix eth_config impl (paradigmxyz#18744) feat: make more EVM and RPC conversions fallible (paradigmxyz#18685) chore: bump rust to edition 2024 (paradigmxyz#18692) chore: release 1.8.1 (paradigmxyz#18646) fix: Revert "chore: disable fee charge in env" (paradigmxyz#18645) chore(deps): bump CodSpeedHQ/action from 3 to 4 (paradigmxyz#18333) chore: update voc.config.to text to v1.8.0 (paradigmxyz#18644) chore: update version to 1.8.0 in Cargo.toml (paradigmxyz#18638) fix: check request gas limit before (paradigmxyz#18639) chore(observability): add tokio runtime with custom thread naming (paradigmxyz#18635) docs: update dashboard table and rpc urls (paradigmxyz#18637) feat: add osaka+bpo timestamps (paradigmxyz#18627) chore: disable fee charge in env (paradigmxyz#18634) chore: bump inspectors 0.30 (paradigmxyz#18633) ...
closes: #18572