Skip to content

chore: bump rust to edition 2024#18692

Merged
mediocregopher merged 28 commits intomainfrom
yk/update_rust_2024
Sep 25, 2025
Merged

chore: bump rust to edition 2024#18692
mediocregopher merged 28 commits intomainfrom
yk/update_rust_2024

Conversation

@yongkangc
Copy link
Member

closes: #18572

…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.
@yongkangc yongkangc requested a review from Copilot September 25, 2025 08:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 let patterns in if let statements
  • Updates to configuration files including Cargo.toml, rustfmt.toml, and various example manifests
  • Safety-related changes to unsafe function 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.

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Sep 25, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Sep 25, 2025

CodSpeed Performance Report

Merging #18692 will not alter performance

Comparing yk/update_rust_2024 (d297bf8) with main (a31dce9)

Summary

✅ 77 untouched

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.

// 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
Copy link
Member Author

@yongkangc yongkangc Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 +         } };

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @mattsse for review here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@mediocregopher mediocregopher added this pull request to the merge queue Sep 25, 2025
Merged via the queue into main with commit a047a05 Sep 25, 2025
41 checks passed
@mediocregopher mediocregopher deleted the yk/update_rust_2024 branch September 25, 2025 12:35
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Sep 25, 2025
@jenpaff jenpaff moved this from Done to Completed in Reth Tracker Sep 29, 2025
shekhirin pushed a commit that referenced this pull request Sep 30, 2025
Vui-Chee added a commit to okx/reth that referenced this pull request Nov 3, 2025
* 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)
  ...
theochap pushed a commit to ethereum-optimism/optimism that referenced this pull request Jan 22, 2026
theochap pushed a commit to ethereum-optimism/optimism that referenced this pull request Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Completed

Development

Successfully merging this pull request may close these issues.

Update to edition 2024

5 participants