Skip to content

Commit d7e76ba

Browse files
fix(rust): satisfy clippy 1.96 lints
Rust 1.96 added new clippy lints that broke the workspace with `-D warnings`: - `unnecessary_sort_by` on the CLI help codegen `sort_by` calls: switched to `sort_by_key`. - `manual_is_multiple_of` on the Codex leap-year helper: switched to `u16::is_multiple_of`. - `unnecessary_unwrap` on the pricing override branches: switched to `if let Some(value) = …`. - `unused_imports` on the `ccusage-test-support` tests module: dropped the redundant `use crate::fs_fixture` since the macro is `#[macro_export]` and is referenced via the macro_rules name directly. Co-authored-by: Codesmith <[email protected]>
1 parent 3670758 commit d7e76ba

4 files changed

Lines changed: 7 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn generate_option_functions(
2323
) -> BTreeMap<String, String> {
2424
let mut rendered_options = BTreeMap::new();
2525
let mut option_sets = option_sets.iter().collect::<Vec<_>>();
26-
option_sets.sort_by(|(left, _), (right, _)| left.cmp(right));
26+
option_sets.sort_by_key(|(left, _)| *left);
2727
for (function_name, options) in option_sets {
2828
let rendered = render_options(options);
2929
rendered_options.insert(function_name.to_string(), rendered.clone());
@@ -32,7 +32,7 @@ fn generate_option_functions(
3232

3333
let combined_options = object_field(command_spec, "combinedOptions");
3434
let mut combined_options = combined_options.iter().collect::<Vec<_>>();
35-
combined_options.sort_by(|(left, _), (right, _)| left.cmp(right));
35+
combined_options.sort_by_key(|(left, _)| *left);
3636
for (function_name, parts) in combined_options {
3737
let Value::Array(parts) = parts else {
3838
panic!("combined option parts must be an array");

‎rust/crates/ccusage-test-support/src/lib.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ macro_rules! fs_fixture {
7373

7474
#[cfg(test)]
7575
mod tests {
76-
use crate::fs_fixture;
77-
7876
#[test]
7977
fn creates_inline_fixture_tree() {
8078
let fixture = fs_fixture!({

‎rust/crates/ccusage/src/adapter/codex/parser.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ fn codex_days_in_month(year: u16, month: u16) -> Option<u16> {
570570
}
571571

572572
fn codex_is_leap_year(year: u16) -> bool {
573-
year % 4 == 0 && year % 100 != 0 || year % 400 == 0
573+
year.is_multiple_of(4) && !year.is_multiple_of(100) || year.is_multiple_of(400)
574574
}
575575

576576
fn codex_session_id(sessions_dir: &Path, path: &Path) -> String {

‎rust/crates/ccusage/src/pricing.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,16 @@ impl PricingMap {
469469
1.0
470470
};
471471

472-
let cache_create = if override_value.cache_creation_input_token_cost.is_some() {
473-
override_value.cache_creation_input_token_cost.unwrap()
472+
let cache_create = if let Some(value) = override_value.cache_creation_input_token_cost {
473+
value
474474
} else if should_scale && base.cache_create > 0.0 {
475475
base.cache_create * scale
476476
} else {
477477
base.cache_create
478478
};
479479

480-
let cache_read = if override_value.cache_read_input_token_cost.is_some() {
481-
override_value.cache_read_input_token_cost.unwrap()
480+
let cache_read = if let Some(value) = override_value.cache_read_input_token_cost {
481+
value
482482
} else if should_scale && base.cache_read > 0.0 {
483483
base.cache_read * scale
484484
} else {

0 commit comments

Comments
 (0)