From 8b4912d5a2d023cf775d0685763c3b341e5c33d0 Mon Sep 17 00:00:00 2001 From: JamBalaya56562 Date: Sat, 1 Aug 2026 18:00:56 +0900 Subject: [PATCH] style: fix clippy and deprecation warnings in test and bench targets `lint:clippy` runs `cargo clippy --all --all-features -- -D warnings`, which does not cover test, bench or example targets. Nothing was linting them, so they had drifted: - `lib/benches/parse.rs` used `criterion::black_box`, deprecated in favour of `std::hint::black_box`. Importing it from `std::hint` fixes all 13 call sites without touching them. - `lib/src/parse.rs` used `get(k).is_none()` where `!contains_key(k)` says the same thing (`clippy::unnecessary_get_then_check`). - `cli/tests/shell_completions_integration.rs` used `iter().any(|l| *l == x)` where `contains(&x)` is equivalent and cheaper (`clippy::manual_contains`). `cargo clippy --all --all-features --all-targets -- -D warnings` is now clean. No behaviour changes. --- cli/tests/shell_completions_integration.rs | 6 ++---- lib/benches/parse.rs | 3 ++- lib/src/parse.rs | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/cli/tests/shell_completions_integration.rs b/cli/tests/shell_completions_integration.rs index 47581270..bd4e432a 100644 --- a/cli/tests/shell_completions_integration.rs +++ b/cli/tests/shell_completions_integration.rs @@ -1012,14 +1012,12 @@ cmd other help="Another subcommand" let lines: Vec<&str> = output.lines().collect(); assert!( - lines.iter().any(|l| *l == "sub\tA subcommand\tsub"), + lines.contains(&"sub\tA subcommand\tsub"), "Expected 'sub\\tA subcommand\\tsub' in zsh output, got: {:?}", lines ); assert!( - lines - .iter() - .any(|l| *l == "other\tAnother subcommand\tother"), + lines.contains(&"other\tAnother subcommand\tother"), "Expected 'other\\tAnother subcommand\\tother' in zsh output, got: {:?}", lines ); diff --git a/lib/benches/parse.rs b/lib/benches/parse.rs index 29c8a021..b919ef9c 100644 --- a/lib/benches/parse.rs +++ b/lib/benches/parse.rs @@ -1,4 +1,5 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{criterion_group, criterion_main, Criterion}; +use std::hint::black_box; use usage::{parse, Spec, SpecArg, SpecCommand, SpecFlag}; fn build_small_spec() -> Spec { diff --git a/lib/src/parse.rs b/lib/src/parse.rs index 84c96c14..84df8960 100644 --- a/lib/src/parse.rs +++ b/lib/src/parse.rs @@ -2048,11 +2048,11 @@ mod tests { // (d) Negative case: a purely-local flag that shares nothing with a global is NOT // promoted/merged — it is correctly dropped when descending into the mount. assert!( - parsed.available_flags.get("-f").is_none(), + !parsed.available_flags.contains_key("-f"), "purely-local -f must not be promoted onto a global", ); assert!( - parsed.available_flags.get("--force").is_none(), + !parsed.available_flags.contains_key("--force"), "purely-local --force must not be promoted onto a global", );