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
This commit is contained in:
Stefan Holderbach
2025-08-19 16:39:48 +02:00
committed by GitHub
parent 43a308f629
commit 5a7d9062a1
10 changed files with 14 additions and 63 deletions

View File

@@ -1,7 +0,0 @@
use super::db_table::DbTable;
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct DbSchema {
pub name: String,
pub tables: Vec<DbTable>,
}

View File

@@ -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;

View File

@@ -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))

View File

@@ -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<bool, Box<dyn Error>>
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<bool> {
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)
}
}

View File

@@ -85,7 +85,7 @@ enum Pick {
}
pub fn median(values: &[Value], span: Span, head: Span) -> Result<Value, ShellError> {
let take = if values.len() % 2 == 0 {
let take = if values.len().is_multiple_of(2) {
Pick::MedianAverage
} else {
Pick::Median

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -2861,7 +2861,7 @@ impl<Form: PathForm> Eq for Path<Form> {}
impl<Form: PathForm> PartialOrd for Path<Form> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.inner.cmp(&other.inner))
Some(self.cmp(other))
}
}
@@ -2887,7 +2887,7 @@ impl<Form: PathForm> Eq for PathBuf<Form> {}
impl<Form: PathForm> PartialOrd for PathBuf<Form> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.inner.cmp(&other.inner))
Some(self.cmp(other))
}
}

View File

@@ -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 {
" "

View File

@@ -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