From 5a7d9062a1b33e759d89acb8482118996ed9a267 Mon Sep 17 00:00:00 2001 From: Stefan Holderbach Date: Tue, 19 Aug 2025 16:39:48 +0200 Subject: [PATCH] chore: Clippy and dead code elimination pass (#16469) - **Fix `clippy::non_canonical_partial_ord_impl`** - **Clippy from stable `needless_return`** - **Dead code found by `cargo +stable clippy`** - **Remove dead function used by pre-uu `mv --update`** - **clippy::manual_is_multiple_of** ## Release notes summary - What our users need to know N/A --- .../database/values/definitions/db_schema.rs | 7 --- .../src/database/values/definitions/mod.rs | 1 - .../nu-command/src/database/values/sqlite.rs | 2 +- crates/nu-command/src/filesystem/util.rs | 44 +------------------ crates/nu-command/src/math/median.rs | 2 +- crates/nu-command/src/platform/ulimit.rs | 4 +- crates/nu-parser/src/parser.rs | 3 +- crates/nu-path/src/path.rs | 4 +- crates/nu-pretty-hex/src/pretty_hex.rs | 4 +- crates/nu-term-grid/src/grid.rs | 6 +-- 10 files changed, 14 insertions(+), 63 deletions(-) delete mode 100644 crates/nu-command/src/database/values/definitions/db_schema.rs diff --git a/crates/nu-command/src/database/values/definitions/db_schema.rs b/crates/nu-command/src/database/values/definitions/db_schema.rs deleted file mode 100644 index 8df11c00c1..0000000000 --- a/crates/nu-command/src/database/values/definitions/db_schema.rs +++ /dev/null @@ -1,7 +0,0 @@ -use super::db_table::DbTable; - -#[derive(Clone, PartialEq, Eq, Debug)] -pub struct DbSchema { - pub name: String, - pub tables: Vec, -} diff --git a/crates/nu-command/src/database/values/definitions/mod.rs b/crates/nu-command/src/database/values/definitions/mod.rs index 95fcc10b4c..6e034f248d 100644 --- a/crates/nu-command/src/database/values/definitions/mod.rs +++ b/crates/nu-command/src/database/values/definitions/mod.rs @@ -3,5 +3,4 @@ pub mod db_constraint; pub mod db_foreignkey; pub mod db_index; pub mod db_row; -pub mod db_schema; pub mod db_table; diff --git a/crates/nu-command/src/database/values/sqlite.rs b/crates/nu-command/src/database/values/sqlite.rs index 32631a7f0e..168a487b0a 100644 --- a/crates/nu-command/src/database/values/sqlite.rs +++ b/crates/nu-command/src/database/values/sqlite.rs @@ -619,7 +619,7 @@ fn prepared_statement_to_nu_list( // got heavily in the way let row_values = match params { NuSqlParams::List(params) => { - let refs: Vec<&dyn ToSql> = params.iter().map(|value| (&**value)).collect(); + let refs: Vec<&dyn ToSql> = params.iter().map(|value| &**value).collect(); let row_results = stmt.query_map(refs.as_slice(), |row| { Ok(convert_sqlite_row_to_nu_value(row, call_span, &columns)) diff --git a/crates/nu-command/src/filesystem/util.rs b/crates/nu-command/src/filesystem/util.rs index 74a6fb14e9..22d7a7922c 100644 --- a/crates/nu-command/src/filesystem/util.rs +++ b/crates/nu-command/src/filesystem/util.rs @@ -1,16 +1,5 @@ use dialoguer::Input; -use std::{ - error::Error, - path::{Path, PathBuf}, -}; - -#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)] -pub struct Resource { - pub at: usize, - pub location: PathBuf, -} - -impl Resource {} +use std::error::Error; pub fn try_interaction( interactive: bool, @@ -56,34 +45,3 @@ fn get_interactive_confirmation(prompt: String) -> Result> Ok(false) } } - -/// Return `Some(true)` if the last change time of the `src` old than the `dst`, -/// otherwisie return `Some(false)`. Return `None` if the `src` or `dst` doesn't exist. -#[allow(dead_code)] -pub fn is_older(src: &Path, dst: &Path) -> Option { - if !dst.exists() || !src.exists() { - return None; - } - #[cfg(unix)] - { - use std::os::unix::fs::MetadataExt; - let src_ctime = std::fs::metadata(src) - .map(|m| m.ctime()) - .unwrap_or(i64::MIN); - let dst_ctime = std::fs::metadata(dst) - .map(|m| m.ctime()) - .unwrap_or(i64::MAX); - Some(src_ctime <= dst_ctime) - } - #[cfg(windows)] - { - use std::os::windows::fs::MetadataExt; - let src_ctime = std::fs::metadata(src) - .map(|m| m.last_write_time()) - .unwrap_or(u64::MIN); - let dst_ctime = std::fs::metadata(dst) - .map(|m| m.last_write_time()) - .unwrap_or(u64::MAX); - Some(src_ctime <= dst_ctime) - } -} diff --git a/crates/nu-command/src/math/median.rs b/crates/nu-command/src/math/median.rs index ae1471cadf..3b9a6ee936 100644 --- a/crates/nu-command/src/math/median.rs +++ b/crates/nu-command/src/math/median.rs @@ -85,7 +85,7 @@ enum Pick { } pub fn median(values: &[Value], span: Span, head: Span) -> Result { - let take = if values.len() % 2 == 0 { + let take = if values.len().is_multiple_of(2) { Pick::MedianAverage } else { Pick::Median diff --git a/crates/nu-command/src/platform/ulimit.rs b/crates/nu-command/src/platform/ulimit.rs index 762eade546..c8e36a72cd 100644 --- a/crates/nu-command/src/platform/ulimit.rs +++ b/crates/nu-command/src/platform/ulimit.rs @@ -474,11 +474,11 @@ fn parse_limit( } else if val == "hard" { Ok(hard_limit) } else { - return Err(ShellError::IncorrectValue { + Err(ShellError::IncorrectValue { msg: "Only unlimited, soft and hard are supported for strings".into(), val_span, call_span, - }); + }) } } _ => Err(ShellError::TypeMismatch { diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index b7d44b1ee3..686deb5bf0 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -2197,7 +2197,8 @@ pub fn parse_string_interpolation(working_set: &mut StateWorkingSet, span: Span) 0 }; - if current_byte == b'(' && (!double_quote || preceding_consecutive_backslashes % 2 == 0) + if current_byte == b'(' + && (!double_quote || preceding_consecutive_backslashes.is_multiple_of(2)) { mode = InterpolationMode::Expression; if token_start < b { diff --git a/crates/nu-path/src/path.rs b/crates/nu-path/src/path.rs index 5670ae9657..d4f4a313af 100644 --- a/crates/nu-path/src/path.rs +++ b/crates/nu-path/src/path.rs @@ -2861,7 +2861,7 @@ impl Eq for Path
{} impl PartialOrd for Path { fn partial_cmp(&self, other: &Self) -> Option { - Some(self.inner.cmp(&other.inner)) + Some(self.cmp(other)) } } @@ -2887,7 +2887,7 @@ impl Eq for PathBuf {} impl PartialOrd for PathBuf { fn partial_cmp(&self, other: &Self) -> Option { - Some(self.inner.cmp(&other.inner)) + Some(self.cmp(other)) } } diff --git a/crates/nu-pretty-hex/src/pretty_hex.rs b/crates/nu-pretty-hex/src/pretty_hex.rs index 2fab2a9b43..1fbf6db9ce 100644 --- a/crates/nu-pretty-hex/src/pretty_hex.rs +++ b/crates/nu-pretty-hex/src/pretty_hex.rs @@ -88,8 +88,8 @@ impl HexConfig { } fn delimiter(&self, i: usize) -> &'static str { - if i > 0 && self.chunk > 0 && i % self.chunk == 0 { - if self.group > 0 && i % (self.group * self.chunk) == 0 { + if i > 0 && self.chunk > 0 && i.is_multiple_of(self.chunk) { + if self.group > 0 && i.is_multiple_of(self.group * self.chunk) { " " } else { " " diff --git a/crates/nu-term-grid/src/grid.rs b/crates/nu-term-grid/src/grid.rs index cfbdc307d1..394766c334 100644 --- a/crates/nu-term-grid/src/grid.rs +++ b/crates/nu-term-grid/src/grid.rs @@ -282,7 +282,7 @@ impl Grid { fn columns_dimensions(&self, num_columns: usize) -> Dimensions { let mut num_lines = self.cells.len() / num_columns; - if self.cells.len() % num_columns != 0 { + if !self.cells.len().is_multiple_of(num_columns) { num_lines += 1; } @@ -315,7 +315,7 @@ impl Grid { col_total_width_so_far += cell.width; } else { let mut theoretical_max_num_lines = self.cell_count / theoretical_min_num_cols; - if self.cell_count % theoretical_min_num_cols != 0 { + if !self.cell_count.is_multiple_of(theoretical_min_num_cols) { theoretical_max_num_lines += 1; } return theoretical_max_num_lines; @@ -374,7 +374,7 @@ impl Grid { // The number of columns is the number of cells divided by the number // of lines, *rounded up*. let mut num_columns = self.cell_count / num_lines; - if self.cell_count % num_lines != 0 { + if !self.cell_count.is_multiple_of(num_lines) { num_columns += 1; } // Early abort: if there are so many columns that the width of the