Skip to content

Commit 5816e64

Browse files
authored
build(rust): migrate crates to edition 2024 (#1308)
* build(rust): migrate crates to edition 2024 Update all Rust crate manifests from edition 2021 to 2024 now that the workspace toolchain is on Rust 1.96. Align treefmt rustfmt configuration with the crate edition so local formatting and flake checks use the same parser mode. Apply cargo fix, clippy --fix, and rustfmt output for edition-compatibility changes such as env var unsafe calls, expr_2021 macro fragments, let-chain collapses, and import ordering. * test(rust): centralize environment variable guards Add a shared test-support environment variable guard that holds a single process-wide mutex while temporarily setting environment variables. Replace module-local locks and direct unsafe env mutations in tests with the shared RAII guard so Rust 2024 unsafe environment access is isolated in one audited helper and restored consistently.
1 parent a414a4d commit 5816e64

100 files changed

Lines changed: 554 additions & 691 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎nix/treefmt.nix‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ in
7070
nixfmt.enable = true;
7171
rustfmt = {
7272
enable = true;
73-
edition = "2021";
73+
edition = "2024";
7474
package = rustToolchain;
7575
};
7676
statix.enable = true;

‎rust/crates/ccusage-cli/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ccusage-cli"
33
version = "20.0.11"
4-
edition = "2021"
4+
edition = "2024"
55
build = "build.rs"
66

77
[dependencies]

‎rust/crates/ccusage-cli/src/help_codegen.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ fn generate_command_spec(
130130
let usage = string_field(page, "usage");
131131
let commands = optional_array_field(page, "commands");
132132
let option_set = optional_string_field(page, "options");
133-
if let Some(option_set) = option_set.as_deref() {
134-
if !rendered_options.contains_key(option_set) {
135-
panic!("missing option set {option_set}");
136-
}
133+
if let Some(option_set) = option_set.as_deref()
134+
&& !rendered_options.contains_key(option_set)
135+
{
136+
panic!("missing option set {option_set}");
137137
}
138138
output.push_str(" HelpPage {\n");
139139
output.push_str(" path: &");

‎rust/crates/ccusage-cli/src/lib.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ mod parser;
44
mod types;
55

66
pub use types::{
7-
normalize_date_bound, AgentCommandArgs, AgentReportKind, BlocksArgs, Cli, CliConfig,
8-
CodexSpeed, Command, CostMode, CostSource, DailyArgs, NoConfig, PricingOverride, SessionArgs,
9-
SharedArgs, SortOrder, StatuslineArgs, VisualBurnRate, WeekDay, WeeklyArgs,
7+
AgentCommandArgs, AgentReportKind, BlocksArgs, Cli, CliConfig, CodexSpeed, Command, CostMode,
8+
CostSource, DailyArgs, NoConfig, PricingOverride, SessionArgs, SharedArgs, SortOrder,
9+
StatuslineArgs, VisualBurnRate, WeekDay, WeeklyArgs, normalize_date_bound,
1010
};
1111

1212
#[cfg(test)]

‎rust/crates/ccusage-cli/src/parser.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use crate::arg_parser::ArgParser;
44
use crate::help::{print_help_and_exit, print_version_and_exit};
55
use crate::types::{OPENCODE_AGENT_REPORTS, STANDARD_AGENT_REPORTS};
66
use crate::{
7-
normalize_date_bound, AgentCommandArgs, AgentReportKind, BlocksArgs, Cli, CliConfig,
8-
CodexSpeed, Command, CostMode, CostSource, DailyArgs, NoConfig, SessionArgs, SharedArgs,
9-
SortOrder, StatuslineArgs, VisualBurnRate, WeekDay, WeeklyArgs,
7+
AgentCommandArgs, AgentReportKind, BlocksArgs, Cli, CliConfig, CodexSpeed, Command, CostMode,
8+
CostSource, DailyArgs, NoConfig, SessionArgs, SharedArgs, SortOrder, StatuslineArgs,
9+
VisualBurnRate, WeekDay, WeeklyArgs, normalize_date_bound,
1010
};
1111

1212
#[derive(Clone, Copy, Debug, Eq, PartialEq)]

‎rust/crates/ccusage-cli/src/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ffi::OsString;
22

3-
use serde_json::{json, Value};
3+
use serde_json::{Value, json};
44

55
use crate::help::{help_text, help_text_for_args};
66
use crate::*;

‎rust/crates/ccusage-terminal/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "ccusage-terminal"
33
version = "20.0.11"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
terminal_size = "0.4.4"

‎rust/crates/ccusage-terminal/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod terminal;
44
mod title;
55
mod width;
66

7-
pub use style::{color, Color, TerminalStyle};
7+
pub use style::{Color, TerminalStyle, color};
88
pub use table::{Align, SimpleTable};
99
pub use terminal::terminal_width;
1010
pub use title::print_box_title;

‎rust/crates/ccusage-terminal/src/table.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::io::{self, Write};
22

33
use crate::{
4-
style::{color, Color, TerminalStyle},
4+
style::{Color, TerminalStyle, color},
55
terminal::DEFAULT_TERMINAL_WIDTH,
66
width::{char_display_width, contains_ansi, visible_width, visible_width_max_line},
77
};
@@ -139,10 +139,10 @@ impl SimpleTable {
139139
return row.to_vec();
140140
}
141141
let mut row = row.to_vec();
142-
if let Some(first) = row.first_mut() {
143-
if let Some(compact) = compact_date_cell(first) {
144-
*first = compact;
145-
}
142+
if let Some(first) = row.first_mut()
143+
&& let Some(compact) = compact_date_cell(first)
144+
{
145+
*first = compact;
146146
}
147147
row
148148
}

‎rust/crates/ccusage-terminal/src/title.rs‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
style::{color, Color, TerminalStyle},
2+
style::{Color, TerminalStyle, color},
33
width::visible_width,
44
};
55

@@ -57,12 +57,16 @@ mod tests {
5757
},
5858
);
5959

60-
assert!(lines
61-
.iter()
62-
.any(|line| line.contains("Coding (Agent) CLI Usage Report - Daily")));
63-
assert!(lines
64-
.iter()
65-
.any(|line| line.contains("Detected: Claude, Codex")));
60+
assert!(
61+
lines
62+
.iter()
63+
.any(|line| line.contains("Coding (Agent) CLI Usage Report - Daily"))
64+
);
65+
assert!(
66+
lines
67+
.iter()
68+
.any(|line| line.contains("Detected: Claude, Codex"))
69+
);
6670
assert_eq!(lines.iter().filter(|line| line.starts_with('╭')).count(), 1);
6771
assert_eq!(lines.iter().filter(|line| line.starts_with('╰')).count(), 1);
6872
}

0 commit comments

Comments
 (0)