Problem / Background
The codebase currently uses Rust 2021 edition (edition = "2021" in Cargo.toml). Rust 2024 edition is now stable and brings several language changes that affect this project. Migration should be done proactively to stay current and benefit from new language features.
Running cargo fix --edition and the edition migration lint reveals 4 areas of required changes, ordered below by risk and difficulty. The current toolchain is rustc 1.94.1.
Migration Areas
1. [HIGH RISK] Temporary value drop order changes (21 warnings, NOT auto-fixable)
Rust 2024 changes the drop order of temporary values in tail expressions. This is the most dangerous area because it can cause runtime behavioral changes including potential deadlocks.
Affected files:
src/device/readers/tpu_grpc.rs:120 — A MutexGuard is held while create_channel().await produces temporaries whose drop order changes. The lock release timing could change, risking deadlock in async context.
src/main.rs — TerminalManager has a custom Drop impl (terminal restoration). Drop order change could cause terminal state corruption on exit.
src/view/data_collection/local_collector.rs — Similar temporary drop order issues with async operations.
Fix approach: Manually review each warning site. Bind temporaries to explicit let variables to make drop order deterministic and edition-independent. Each site needs case-by-case analysis of the Drop implementations involved.
Reference: https://doc.rust-lang.org/edition-guide/rust-2024/temporary-tail-expr-scope.html
2. [MEDIUM RISK] gen keyword reservation
Rust 2024 reserves gen as a keyword (for future generator syntax). The codebase uses gen as variable/field names in multiple places:
src/api/metrics/gpu.rs — local variable gen from PCIe generation parsing
src/api/metrics/npu/tenstorrent.rs — same pattern
src/device/readers/amd.rs — 5 occurrences accessing link.gen field from external amdgpu crate
src/device/readers/nvidia.rs — similar usage
Fix approach:
- For local variables: rename to
pcie_gen or generation.
- For external crate fields (e.g.,
link.gen from amdgpu crate): must use r#gen raw identifier syntax until upstream crate updates. Check if upstream crates have 2024-edition-compatible releases.
3. [LOW RISK] Macro expr fragment specifier changes (32+ fixes, auto-fixable)
Rust 2024 expands what $x:expr matches (now includes const { ... } blocks). cargo fix --edition auto-converts to $x:expr_2021 to preserve behavior, but this is a transitional specifier.
Affected files:
src/parsing/macros.rs — 32 occurrences
src/common/error_handling.rs — 3 macros (handle_error!, log_error_default!, log_error_return!)
src/device/readers/common_cache.rs — 2 macros (build_detail_map!, cache_device_static_info!)
Fix approach: For most macros in this project, accepting the broader expr (2024 semantics) is fine. Review each macro to decide: use new $x:expr (accepts more syntax) or explicitly restrict with $x:expr_2021.
4. [LOW RISK] ref in if let patterns + if let chaining (auto-fixable)
Rust 2024 makes ref unnecessary in if let Some(ref x) patterns due to improved ergonomics, and changes how if let chains work.
Affected files:
src/device/memory_linux.rs — 1 occurrence
src/device/memory_linux/tests.rs — 3 occurrences
src/device/readers/nvidia.rs — if let Ok(status) = NVML_STATUS.lock() converted to match expression
Fix approach: Simple mechanical changes: if let Some(ref x) becomes if let Some(x).
Acceptance Criteria
Technical Considerations
- The HIGH RISK items (drop order) cannot be auto-fixed and require careful manual review. Incorrect handling can lead to deadlocks or terminal corruption at runtime without any compile-time warning.
- The
gen keyword issue may require coordination with upstream crate maintainers (particularly the amdgpu crate).
- The macro and
ref changes are largely mechanical and can be auto-fixed, but should be reviewed for correctness.
- Consider running the migration in phases: fix all issues first on 2021 edition (edition-compatible fixes), then flip the edition flag last.
Problem / Background
The codebase currently uses Rust 2021 edition (
edition = "2021"inCargo.toml). Rust 2024 edition is now stable and brings several language changes that affect this project. Migration should be done proactively to stay current and benefit from new language features.Running
cargo fix --editionand the edition migration lint reveals 4 areas of required changes, ordered below by risk and difficulty. The current toolchain is rustc 1.94.1.Migration Areas
1. [HIGH RISK] Temporary value drop order changes (21 warnings, NOT auto-fixable)
Rust 2024 changes the drop order of temporary values in tail expressions. This is the most dangerous area because it can cause runtime behavioral changes including potential deadlocks.
Affected files:
src/device/readers/tpu_grpc.rs:120— AMutexGuardis held whilecreate_channel().awaitproduces temporaries whose drop order changes. The lock release timing could change, risking deadlock in async context.src/main.rs—TerminalManagerhas a customDropimpl (terminal restoration). Drop order change could cause terminal state corruption on exit.src/view/data_collection/local_collector.rs— Similar temporary drop order issues with async operations.Fix approach: Manually review each warning site. Bind temporaries to explicit
letvariables to make drop order deterministic and edition-independent. Each site needs case-by-case analysis of theDropimplementations involved.Reference: https://doc.rust-lang.org/edition-guide/rust-2024/temporary-tail-expr-scope.html
2. [MEDIUM RISK]
genkeyword reservationRust 2024 reserves
genas a keyword (for future generator syntax). The codebase usesgenas variable/field names in multiple places:src/api/metrics/gpu.rs— local variablegenfrom PCIe generation parsingsrc/api/metrics/npu/tenstorrent.rs— same patternsrc/device/readers/amd.rs— 5 occurrences accessinglink.genfield from externalamdgpucratesrc/device/readers/nvidia.rs— similar usageFix approach:
pcie_genorgeneration.link.genfromamdgpucrate): must user#genraw identifier syntax until upstream crate updates. Check if upstream crates have 2024-edition-compatible releases.3. [LOW RISK] Macro
exprfragment specifier changes (32+ fixes, auto-fixable)Rust 2024 expands what
$x:exprmatches (now includesconst { ... }blocks).cargo fix --editionauto-converts to$x:expr_2021to preserve behavior, but this is a transitional specifier.Affected files:
src/parsing/macros.rs— 32 occurrencessrc/common/error_handling.rs— 3 macros (handle_error!,log_error_default!,log_error_return!)src/device/readers/common_cache.rs— 2 macros (build_detail_map!,cache_device_static_info!)Fix approach: For most macros in this project, accepting the broader
expr(2024 semantics) is fine. Review each macro to decide: use new$x:expr(accepts more syntax) or explicitly restrict with$x:expr_2021.4. [LOW RISK]
refinif letpatterns +if letchaining (auto-fixable)Rust 2024 makes
refunnecessary inif let Some(ref x)patterns due to improved ergonomics, and changes howif letchains work.Affected files:
src/device/memory_linux.rs— 1 occurrencesrc/device/memory_linux/tests.rs— 3 occurrencessrc/device/readers/nvidia.rs—if let Ok(status) = NVML_STATUS.lock()converted to match expressionFix approach: Simple mechanical changes:
if let Some(ref x)becomesif let Some(x).Acceptance Criteria
tpu_grpc.rs(bind temporaries to let variables, verify no deadlock)main.rs(ensure TerminalManager drops correctly)local_collector.rsgenvariables to non-keyword names (pcie_genorgeneration)genfields (check upstream, user#genif needed)expr_2021vsexpr)refinif letpatternsCargo.tomledition from"2021"to"2024"Technical Considerations
genkeyword issue may require coordination with upstream crate maintainers (particularly theamdgpucrate).refchanges are largely mechanical and can be auto-fixed, but should be reviewed for correctness.