Skip to content

Commit f2d156f

Browse files
fix(clippy): clear 86 errors under -D warnings across impl/rust-cli/ (#74)
* fix(clippy): clear 86 errors under -D warnings across impl/rust-cli/ Combined auto-fix (`cargo clippy --fix`) for 60 mechanical lints + manual fixes for the remaining 26 across 34 files. Manual categories handled: - `&PathBuf` → `&Path` (process_sub.rs ×2) - `assert!(true)`, `assert!(len() >= 0)` removed (parser.rs, confirmation.rs, e2e_script_execution.rs) - `manual_strip` → `strip_prefix` (functions.rs, state.rs, parser.rs) - `format!` collapsed into outer `print!`/`println!` (pager.rs, commands.rs) - `impl Default for RedirectSetup` - doc_lazy_continuation: orphan doc block removed; new doc with blank line before - empty_line_after_doc_comments: stray doc-comment without item removed - unused_unsafe block removed from libc::WIFSTOPPED call - needless_range_loop on Token slice → iterator + take/skip - unused_doc_comments on macro invocations (proptest!) → plain `//` comments Allow-listed (lint suggestion would change semantics or require unrelated refactor; documented at each site): - needless_range_loop on 2-D matrix init (correction.rs ×2) - if_same_then_else on shell-operator branches (highlighter.rs) - private_interfaces + dead_code on `expand_quoted_word_with_state` - unused_assignments inside push_word! macro (parser.rs) - should_implement_trait on TrapSignal::from_str (custom Option return) - join_absolute_paths in sandbox-escape test (intentional) - dead_code on test fixture helpers (populated_sandbox, dir_path, any_name, word) Verification: `cargo clippy --all-targets --all-features -- -D warnings` exits clean; `cargo test --release` reports 757 passed / 0 failed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(fmt): apply cargo fmt to clear --check drift from PR #73 PR #73's fmt sweep agent ran an older rustfmt; CI's stable rustfmt sees 8 files needing reformat (mostly merged-multiline-args + trailing- whitespace + match-arm-wrap). Apply the corrections. Verified: `cargo fmt --check` clean, `cargo clippy -D warnings` clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f6c6aa8 commit f2d156f

34 files changed

Lines changed: 198 additions & 232 deletions

impl/rust-cli/benches/performance_benchmarks.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
1717
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
1818
use std::fs;
19-
use std::io::Write;
2019
use tempfile::TempDir;
21-
use vsh::commands::{mkdir, redo, rm, touch, undo};
20+
use vsh::commands::{mkdir, redo, undo};
2221
use vsh::glob::expand_glob;
2322
use vsh::state::ShellState;
2423

impl/rust-cli/src/arith.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,15 @@ pub fn eval_arith(expr: &ArithExpr, state: &ShellState) -> Result<i64> {
665665
ArithOp::BitOr => Ok(lval | rval),
666666
ArithOp::BitXor => Ok(lval ^ rval),
667667
ArithOp::ShiftLeft => {
668-
if rval < 0 || rval >= 64 {
668+
if !(0..64).contains(&rval) {
669669
Err(anyhow!("Shift count out of range: {}", rval))
670670
} else {
671671
lval.checked_shl(rval as u32)
672672
.ok_or_else(|| anyhow!("Arithmetic overflow: {} << {}", lval, rval))
673673
}
674674
}
675675
ArithOp::ShiftRight => {
676-
if rval < 0 || rval >= 64 {
676+
if !(0..64).contains(&rval) {
677677
Err(anyhow!("Shift count out of range: {}", rval))
678678
} else {
679679
lval.checked_shr(rval as u32)

impl/rust-cli/src/audit_log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use chrono::{DateTime, Utc};
1515
use serde::{Deserialize, Serialize};
1616
use std::fs::OpenOptions;
1717
use std::io::Write;
18-
use std::path::{Path, PathBuf};
18+
use std::path::PathBuf;
1919
use uuid::Uuid;
2020

2121
use crate::state::Operation;

impl/rust-cli/src/commands.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,7 @@ pub fn show_graph(state: &ShellState) -> Result<()> {
16771677
.unwrap_or_else(|| format!("[non-reversible: {}]", op.path));
16781678
print!("{}", inverse_str.bright_yellow());
16791679
}
1680-
print!(" → [initial]\n");
1680+
println!(" → [initial]");
16811681
}
16821682

16831683
Ok(())
@@ -1797,7 +1797,7 @@ pub fn fg(state: &mut ShellState, job_spec: Option<&str>) -> Result<()> {
17971797
}
17981798

17991799
// Update job state based on wait result
1800-
if unsafe { libc::WIFSTOPPED(status) } {
1800+
if libc::WIFSTOPPED(status) {
18011801
state.jobs.update_job_state(pgid, JobState::Stopped);
18021802
println!(
18031803
"\n[{}]+ Stopped {}",
@@ -2187,7 +2187,7 @@ pub fn explain_command(cmd: &crate::parser::Command, state: &ShellState) -> Resu
21872187
let expanded = crate::parser::expand_variables(path, state);
21882188
let resolved = state.resolve_path(&expanded);
21892189
let parent = resolved.parent();
2190-
let parent_exists = parent.map_or(false, |p| p.exists());
2190+
let parent_exists = parent.is_some_and(|p| p.exists());
21912191
let path_free = !resolved.exists();
21922192
println!(
21932193
" {} Parent exists: {}",
@@ -2222,7 +2222,8 @@ pub fn explain_command(cmd: &crate::parser::Command, state: &ShellState) -> Resu
22222222
resolved.display()
22232223
);
22242224
}
2225-
crate::parser::Command::Chmod { path, .. } | crate::parser::Command::Chown { path, .. } => {
2225+
crate::parser::Command::Chmod { path: _, .. }
2226+
| crate::parser::Command::Chown { path: _, .. } => {
22262227
// Outer arm guarantees we are in {Chmod, Chown}; the inner match
22272228
// exists only to extract the `path` field uniformly. Any other
22282229
// variant here is a structural bug, surfaced as typed error.
@@ -2577,15 +2578,12 @@ pub fn replay(state: &ShellState, start: usize, end: usize) -> Result<()> {
25772578
op.path,
25782579
format!("[op:{}]", &op.id.to_string()[..8]).bright_black()
25792580
);
2580-
println!(
2581-
" State: fs{} ──▶ fs{}",
2582-
if idx == 0 {
2583-
"₀".to_string()
2584-
} else {
2585-
format!("_{}", idx)
2586-
},
2587-
format!("_{}", idx + 1)
2588-
);
2581+
let from_state = if idx == 0 {
2582+
"₀".to_string()
2583+
} else {
2584+
format!("_{}", idx)
2585+
};
2586+
println!(" State: fs{} ──▶ fs_{}", from_state, idx + 1);
25892587
println!(
25902588
" Proof: {} {}",
25912589
proof.theorem.bright_cyan(),

impl/rust-cli/src/commands/secure_deletion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ pub fn obliterate_dir(
434434
#[cfg(test)]
435435
mod tests {
436436
use super::*;
437-
use std::path::PathBuf;
437+
438438
use tempfile::TempDir;
439439

440440
#[test]

impl/rust-cli/src/confirmation.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//!
44
//! SAFETY CRITICAL: Prevents accidental data destruction
55
6-
use anyhow::{bail, Result};
6+
use anyhow::Result;
77
use colored::Colorize;
88
use std::io::{self, Write};
99

@@ -337,7 +337,6 @@ mod tests {
337337

338338
#[test]
339339
fn test_count_files() {
340-
let count = count_files_in_tree("/tmp").unwrap_or(0);
341-
assert!(count >= 0);
340+
let _ = count_files_in_tree("/tmp").unwrap_or(0);
342341
}
343342
}

impl/rust-cli/src/correction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
77
use std::env;
88
use std::fs;
9-
use std::path::PathBuf;
109

1110
/// Calculate Levenshtein distance between two strings
1211
///
@@ -36,9 +35,11 @@ pub fn levenshtein_distance(a: &str, b: &str) -> usize {
3635
let mut matrix = vec![vec![0; len_b + 1]; len_a + 1];
3736

3837
// Initialize first row and column
38+
#[allow(clippy::needless_range_loop)]
3939
for i in 0..=len_a {
4040
matrix[i][0] = i;
4141
}
42+
#[allow(clippy::needless_range_loop)]
4243
for j in 0..=len_b {
4344
matrix[0][j] = j;
4445
}

impl/rust-cli/src/echidna_integration.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
//!
2525
//! Author: Jonathan D.A. Jewell
2626
27-
use std::collections::HashMap;
28-
2927
// =========================================================================
3028
// Core types
3129
// =========================================================================
@@ -355,7 +353,7 @@ mod tests {
355353
let reversibility = registry.by_category(PropertyCategory::Reversibility);
356354
assert!(reversibility.len() >= 5);
357355
let security = registry.by_category(PropertyCategory::Security);
358-
assert!(security.len() >= 1);
356+
assert!(!security.is_empty());
359357
}
360358

361359
#[test]

impl/rust-cli/src/enhanced_repl.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use anyhow::Result;
1212
use nu_ansi_term::{Color, Style};
1313
use reedline::{
1414
default_emacs_keybindings, ColumnarMenu, Completer, DefaultHinter, DefaultValidator, Emacs,
15-
FileBackedHistory, HistoryItem, KeyCode, KeyModifiers, MenuBuilder, Prompt, PromptEditMode,
15+
FileBackedHistory, KeyCode, KeyModifiers, MenuBuilder, Prompt, PromptEditMode,
1616
PromptHistorySearch, PromptHistorySearchStatus, Reedline, ReedlineEvent, ReedlineMenu, Signal,
17-
Span, StyledText, Suggestion,
17+
Span, Suggestion,
1818
};
1919
use std::borrow::Cow;
2020
use std::path::PathBuf;
@@ -180,24 +180,25 @@ fn complete_path(prefix: &str, pos: usize) -> Vec<Suggestion> {
180180
struct VshPrompt {
181181
txn_name: Option<String>,
182182
undo_count: usize,
183+
#[allow(dead_code)]
183184
cwd: String,
184185
continuation: bool,
185186
}
186187

187188
impl Prompt for VshPrompt {
188-
fn render_prompt_left(&self) -> Cow<str> {
189+
fn render_prompt_left(&self) -> Cow<'_, str> {
189190
Cow::Borrowed("")
190191
}
191192

192-
fn render_prompt_right(&self) -> Cow<str> {
193+
fn render_prompt_right(&self) -> Cow<'_, str> {
193194
if let Some(ref txn) = self.txn_name {
194195
Cow::Owned(format!("[txn:{}]", txn))
195196
} else {
196197
Cow::Borrowed("")
197198
}
198199
}
199200

200-
fn render_prompt_indicator(&self, _edit_mode: PromptEditMode) -> Cow<str> {
201+
fn render_prompt_indicator(&self, _edit_mode: PromptEditMode) -> Cow<'_, str> {
201202
if self.continuation {
202203
return Cow::Owned(Color::Yellow.paint("...> ").to_string());
203204
}
@@ -217,14 +218,14 @@ impl Prompt for VshPrompt {
217218
Cow::Owned(format!("{}{}", undo_indicator, txn_indicator))
218219
}
219220

220-
fn render_prompt_multiline_indicator(&self) -> Cow<str> {
221+
fn render_prompt_multiline_indicator(&self) -> Cow<'_, str> {
221222
Cow::Borrowed("...> ")
222223
}
223224

224225
fn render_prompt_history_search_indicator(
225226
&self,
226227
history_search: PromptHistorySearch,
227-
) -> Cow<str> {
228+
) -> Cow<'_, str> {
228229
let prefix = match history_search.status {
229230
PromptHistorySearchStatus::Passing => "",
230231
PromptHistorySearchStatus::Failing => "failing ",

impl/rust-cli/src/executable.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,8 @@ impl ExecutableCommand for Command {
853853

854854
Command::Unset { name } => {
855855
let expanded_name = crate::parser::expand_variables(name, state);
856-
if expanded_name.starts_with("-f ") {
856+
if let Some(func_name) = expanded_name.strip_prefix("-f ") {
857857
// unset -f: remove a function
858-
let func_name = &expanded_name[3..];
859858
if !state.functions.unset(func_name) {
860859
eprintln!("unset: {}: not a function", func_name);
861860
}
@@ -1160,7 +1159,7 @@ impl ExecutableCommand for Command {
11601159
for sig_name in signals {
11611160
let expanded = crate::parser::expand_variables(sig_name, state);
11621161
if let Some(sig) = TrapSignal::from_str(&expanded) {
1163-
state.traps.set(sig, &action);
1162+
state.traps.set(sig, action);
11641163
} else {
11651164
eprintln!("trap: {}: invalid signal specification", expanded);
11661165
}
@@ -1599,12 +1598,12 @@ fn case_pattern_matches(word: &str, pattern: &str) -> bool {
15991598

16001599
/// Simple glob pattern matching for case statements
16011600
fn glob_match(pattern: &str, text: &str) -> bool {
1602-
let mut p = pattern.chars().peekable();
1603-
let mut t = text.chars().peekable();
1601+
let _p = pattern.chars().peekable();
1602+
let _t = text.chars().peekable();
16041603

16051604
glob_match_inner(
1606-
&mut pattern.chars().collect::<Vec<_>>(),
1607-
&mut text.chars().collect::<Vec<_>>(),
1605+
&pattern.chars().collect::<Vec<_>>(),
1606+
&text.chars().collect::<Vec<_>>(),
16081607
0,
16091608
0,
16101609
)

0 commit comments

Comments
 (0)