Skip to content

refactor: migrate to Rust 2024 edition#145

Merged
inureyes merged 6 commits into
mainfrom
refactor/issue-144-migrate-rust-2024-edition
Apr 7, 2026
Merged

refactor: migrate to Rust 2024 edition#145
inureyes merged 6 commits into
mainfrom
refactor/issue-144-migrate-rust-2024-edition

Conversation

@inureyes

@inureyes inureyes commented Apr 7, 2026

Copy link
Copy Markdown
Member

Summary

Migrate the codebase from Rust 2021 edition to Rust 2024 edition (rustc 1.94.1).

Changes by phase:

Phase 1: Fix temporary value drop order (HIGH RISK)

  • Bind async results to explicit let variables before match in tpu_grpc.rs and network/client.rs to prevent drop order changes for MutexGuard and other types with custom Drop implementations.

Phase 2: Rename gen keyword (MEDIUM RISK)

  • Rename local gen variables to generator, pcie_gen_value, or generation since gen is reserved in Rust 2024.
  • Use r#gen for external crate field access (amdgpu crate's link.gen).

Phase 3: Auto-fixable changes (LOW RISK)

  • Change macro expr fragment specifiers to expr_2021 for forward compatibility.
  • Convert if let...else chains to match expressions.
  • Remove unnecessary ref in if let patterns.
  • Add unsafe block inside unsafe fn body.

Phase 4: Edition flip and cleanup

  • Update Cargo.toml edition from "2021" to "2024".
  • Apply Rust 2024 if let chain syntax (collapsible_if).
  • Reorder imports per Rust 2024 formatting rules.
  • Remove explicit ref mut in implicit borrowing patterns.

Closes #144

Test plan

  • cargo check passes with no warnings
  • cargo clippy -- -D warnings passes cleanly
  • cargo fmt -- --check passes
  • cargo test passes (all 19 tests pass)
  • Each phase verified independently before proceeding

inureyes added 6 commits April 7, 2026 17:19
Bind async results to explicit let variables before match expressions
to ensure temporaries are dropped before MutexGuard and other locals
with custom Drop impls, preventing drop order changes in Rust 2024.
Rename local variables named 'gen' to 'pcie_gen_value', 'generation',
or 'generator' since 'gen' becomes a reserved keyword in Rust 2024.
Use r#gen for external crate field access (amdgpu link.gen).
- Change macro expr fragment specifiers to expr_2021 for forward compat
- Convert if-let-else chains to match expressions (Rust 2024 requirement)
- Remove unnecessary ref in if-let patterns
- Add unsafe block inside unsafe fn body (Rust 2024 requirement)
Update edition from 2021 to 2024 and apply all resulting changes:
- Collapse nested if-let blocks using Rust 2024 let-chain syntax
- Reorder imports per Rust 2024 formatting rules
- Fix indentation in let-chain expressions
Remove explicit ref mut binding modifiers in patterns that already
implicitly borrow through &mut references (Rust 2024 requirement).
Also add tmp.pb to .gitignore.
@inureyes inureyes added type:refactor Code refactoring status:review Under review priority:low Low priority issue labels Apr 7, 2026
@inureyes

inureyes commented Apr 7, 2026

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Migrate the codebase from Rust 2021 edition to Rust 2024 edition, addressing drop order changes, keyword reservations, macro fragment specifiers, and formatting.

Findings Addressed

No issues found requiring fixes. The implementation is correct and complete.

Detailed Analysis

DROP ORDER FIXES (HIGH RISK) -- CORRECT

  • tpu_grpc.rs:122: create_channel().await result correctly bound to let channel_result before match, ensuring the temporary is dropped before the MutexGuard in guard. This prevents potential deadlock where the async temporary's destructor could run while the mutex is still held.
  • network/client.rs:332: request.send().await result bound to let send_result, and response.text().await bound to let text_result. Both prevent temporaries from having their drop order change relative to surrounding locals (client, auth_token, etc.).
  • local_collector.rs: if let Ok(...) = timeout(...).await patterns converted to match timeout(...).await -- this ensures RwLockWriteGuard temporaries from the timeout() result have deterministic drop order.
  • main.rs: if let Err(e) = initialize_hlsmi_manager(...) converted to match -- correct, though this is lower risk since initialize_hlsmi_manager returns a simple Result without custom Drop types in the temporaries.

GEN KEYWORD RENAMES (MEDIUM RISK) -- CORRECT AND COMPLETE

  • External crate field link.gen (from libamdgpu_top) correctly uses r#gen raw identifier syntax (5 occurrences in amd.rs).
  • Local variable gen renamed to pcie_gen_value in gpu.rs and tenstorrent.rs metric exporters.
  • Grep confirms no bare gen identifiers remain as variable names in the codebase.

MACRO FRAGMENT SPECIFIERS (LOW RISK) -- CORRECT

  • All $x:expr changed to $x:expr_2021 in macros across parsing/macros.rs, error_handling.rs, common_cache.rs, and nvidia.rs. This is the conservative approach that preserves exact Rust 2021 matching behavior. The $x:ty specifiers are left unchanged (correct, as ty semantics did not change).

REF REMOVAL AND IF-LET CONVERSIONS (LOW RISK) -- CORRECT

  • if let chains correctly collapsed using Rust 2024's let chain syntax (e.g., if let Some(x) = a && let Ok(y) = b).
  • if let ... else patterns correctly converted to match expressions.
  • Unnecessary ref removed from patterns where Rust 2024 match ergonomics apply.

EDITION FLIP -- CORRECT

  • Cargo.toml edition changed from "2021" to "2024".

FORMATTING -- CORRECT

  • Import reordering follows Rust 2024 rustfmt conventions (alphabetical within groups).
  • Long format!() calls reformatted with multi-line arguments.
  • No semantic changes in formatting-only diffs.

MISCELLANEOUS

  • tmp.pb added to .gitignore -- appropriate cleanup.
  • unsafe extern "C" syntax in macOS native files left as-is (already valid in both editions).

Remaining Items

None. All requirements from issue #144 are addressed.

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow (edition change is project-wide)
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass (19 passed, 12 ignored, 0 failed)
  • cargo clippy -- -D warnings passes cleanly
  • cargo check passes with no warnings

@inureyes inureyes added status:done Completed and removed status:review Under review labels Apr 7, 2026
@inureyes inureyes merged commit 4b9a3f6 into main Apr 7, 2026
4 checks passed
@inureyes inureyes deleted the refactor/issue-144-migrate-rust-2024-edition branch April 7, 2026 08:33
@inureyes inureyes self-assigned this Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:low Low priority issue status:done Completed type:refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate to Rust 2024 edition

1 participant